• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to convert unix stamp to date?

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

i used the following code from https://coderanch.com/t/384000/Java-General-intermediate/java/Convert-Unix-TimeStamp-Date-Format



my unix time stamp is 1244466958

But i keep getting Fri Dec 19 14:47:22 CET 1969 when i should be getting Monday, June 8th 2009, 13:15:58 (GMT)

can someone help me ?
 
Sheriff
Posts: 22788
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Declare your unixTime as long instead of int.

Both 1244466958 and 1000 are ints. Therefore, although you assign the result to a long variable, the result of the multiplication is int as well. 1244466958000 is larger than Integer.MAX_VALUE so it will be wrapped to -1073557840.

If you declare unixTime as a long, the result of unixTime * 1000 will also be a long and therefore be 1244466958000.


Alternatively, you can upgrade the 1000 to a long by turning it into 1000L.
 
bryan lim
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see!. here's the code. Perfect! thanks Rob Prime!!!


 
reply
    Bookmark Topic Watch Topic
  • New Topic