aspose file tools*
The moose likes Java in General and the fly likes how to convert Unix epoch time to Java Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to convert Unix epoch time to Java Date" Watch "how to convert Unix epoch time to Java Date" New topic
Author

how to convert Unix epoch time to Java Date

vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Hi
I have Unix epoch time i.e.,"1187813802",
but when i try to convert into to Java Date as below..
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String longModtime = formatter.format(new Date(Long.parseLong("1187813802")));

It should give "2007-08-22 20:16" but its showing Year as 1970,
Could anybody please tell me how to do this.

Thanks in Advance
Vamshi


Thanks,
Vamshidhar Nimbagiri
SCJP 5.0
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Date takes a Long argument as a usable timestamp. That Long value is the number of *milliseconds* since the epoch. A UNIX timestamp is the number of *seconds* since the epoch. Hopefully you can figure it out now
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Sorry,
I didn't got what exactly you are saying
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Originally posted by vamshidhar nimbagiri:
Sorry,
I didn't got what exactly you are saying


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to convert Unix epoch time to Java Date