Gold
Gold

Reputation: 62524

Get unexpected results date when convert long to date

i got this time: 1365443145000

i need to get Sensible date (dd/MM/yyyy)

i try : Date d = new Date(1365443145000L * 1000);

but i got: 45239-03-04

Instead of Correct result is: 08/04/2013 20:45

Upvotes: 1

Views: 39

Answers (1)

Pragnani
Pragnani

Reputation: 20155

Dont' multiply with 1000 as you are getting the time in Milliseconds. You can convert date in milliseconds to Date by using the below code, one by using Date constructor and second by using Calendar

call it like this

Date d=new Date(1365443145000L);
    System.out.println(d.toString());

output: Mon Apr 08 17:45:45 UTC 2013

Check this link

http://www.browxy.com/SubmittedCode/17928

Edit:

To convert required format use this code

 Calendar caldate=Calendar.getInstance();
    caldate.setTimeInMillis(1365443145000L);
    SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy hh:mm");
    String strdate=sdf.format(caldate.getTime());
    System.out.println(strdate);

Upvotes: 2

Related Questions