• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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: 22849
132
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!!!


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic