aspose file tools*
The moose likes Java in General and the fly likes Silly Date Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Silly Date Problem" Watch "Silly Date Problem" New topic
Author

Silly Date Problem

Chris Parr
Greenhorn

Joined: Jan 28, 2012
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Aug 05, 2005
Posts: 3645
    
  15
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.


Joanne
Chris Parr
Greenhorn

Joined: Jan 28, 2012
Posts: 2
Thanks all.

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

Live and learn etc....
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Silly Date Problem