Kalanidhi
Kalanidhi

Reputation: 5092

Wrong output while converting epoch time to human format date and time?

I am newbie in Java. I am trying to convert epoch time human format time. I refereed many web site, every one mentioned below steps but I am getting wrong output.

String format = "dd/MM/yyyy HH:mm:ss";
DateFormat dateFormat = new SimpleDateFormat(format);
String expDate=dateFormat.format(new Date(1478017281));
System.out.println(expDate);

System Output :

18/01/1970 08:03:37

Expected Output:

01/11/2016 21:51:21

Thanks in Advance.

Upvotes: 0

Views: 128

Answers (1)

M B
M B

Reputation: 333

The Date constructor takes a long argument which is supposed to be the time in milliseconds, not seconds. Add 3 0's at the end of it and it will print the expected result.

Upvotes: 4

Related Questions