• 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

Silly Date Problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, a little shameful of me asking this as it should be simple (it's late; perhaps I need to go to bed).

I have a long (1327759217) representing a time after epoch; roughly 2pm this afternoon UK time. I want to take that number and print out the date as a string. Here is my code:



My problem is that this prints a date sometime in 1970, 16/01/1970 09:49 AM to be precise.

This shouldn't be. Going to this site here (click) and inserting 1327759217 gives the right answer, but not the above code even though the javadoc suggests I'm doing things right.

Anyone care to point out my schoolboy error? Please?

Cheers
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't care what that site says, there are way too few digits in that value to represent a date in 2012.

In fact, I just computed 1327784196526 for a few minutes ago.

That's 13 digits, not 10.
 
Saloon Keeper
Posts: 15529
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1300000000 milliseconds is roughly equivalent to 15 days. I'm pretty sure the site is wrong.
 
Stephan van Hulst
Saloon Keeper
Posts: 15529
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, if you read the text below the converter, it says that it uses seconds, not milliseconds. That's where the discrepancy arises.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:1300000000 milliseconds is roughly equivalent to 15 days. I'm pretty sure the site is wrong.


Or giving answers in seconds instead of milliseconds

getTime returns the number of milliseconds elapsed, in your computer's timezone, since 1/1/1970 GMT. Because epoch is measured in seconds, you then want to divide the return value by 1000 to change milliseconds into seconds.

 
Chris Parr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all.

Of course you're right. Like I said, I should have called it a day.

Live and learn etc....
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Parr wrote:Like I said, I should have called it a day.



No, you should have just called it a second, instead of a millisecond.
 
reply
    Bookmark Topic Watch Topic
  • New Topic