Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to convert epoch timestamp to date and time. I have used the following code to convert but it converts to a wrong date, year and time.

String date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
                    .format(new java.util.Date (1319286637/1000));

Expected output was today’s date at some time, but the result I got was:

01/01/1970 05:51:59

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

The Date(long) constructor takes milliseconds. You should be multiplying by 1000, not dividing the epoch time you have.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...