-4

I'm finding a way to store "083752" value (timestamp value in long data format) to Mysql database (type = DateTime). Thus, I need to convert that value to human readable date time. I use following code to do that.

long l = 083752;
Date date = new Date(l);
System.out.println(date.toString());

Edit What i need to do is 83752 => 1/2/1970 4:45:52 AM

But it doesn't works. I followed this page also.

Community
  • 1
  • 1
Lakmal Vithanage
  • 2,767
  • 7
  • 42
  • 58

2 Answers2

1

If the time you are storing the time in millis, then

You may use java.util.Date class and then use SimpleDateFormat to format the Date.

Date date=new Date(millis);

for example:

long l = Long.parseLong("083752"); // mills
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(l);
System.out.println(formatter.format(calendar.getTime())); 

This will return you the date

mohamedrias
  • 18,326
  • 2
  • 38
  • 47
0

I found the answer. Thanks for all who support me.

 long l = Long.parseLong("083752");
 String date1 = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date(l * 1000));
 System.out.println(date1);
Lakmal Vithanage
  • 2,767
  • 7
  • 42
  • 58