Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert Unix epoch time to Java Date

 
vamshidhar nimbagiri
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Corbyn
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
I didn't got what exactly you are saying
 
Chris Corbyn
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vamshidhar nimbagiri:
Sorry,
I didn't got what exactly you are saying


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic