Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Silly Date Problem

 
Chris Parr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1300000000 milliseconds is roughly equivalent to 15 days. I'm pretty sure the site is wrong.
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • 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
  • 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....
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic