简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM