File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes 10000 milliseconds showing as 01:00:10.000 - why ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "10000 milliseconds showing as 01:00:10.000 - why ?" Watch "10000 milliseconds showing as 01:00:10.000 - why ?" New topic
Author

10000 milliseconds showing as 01:00:10.000 - why ?

Pascal Got
Greenhorn

Joined: Mar 05, 2002
Posts: 23
Hi,
I have a problem with the following code... I take the time as "now", add 10 seconds and want to display the difference between the two.

I am expecting to see 00:00:10.000 but I get 01:00:10.000... why ?


The output is :


10000 milliseconds is 10 seconds right ?
so should be January 1st 1970 00:00:10.000 right ?
but it's formatted as 01:00:10.000

All i want is display the difference between 2 dates ... any other way ?
Why ? oh why ?

Thanks

Pascal
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Here's a hint: when I replaced "Europe/London" by "America/Vancouver" the output was this:

Wed Dec 31 16:00:10 PST 1969
diff: 10000
diff: 04:00:10.000 PST
diff: 4:00:10 PM

Any other way to display the difference between two dates? Well, yes, any other way would be preferable. You already have 10,000 milliseconds. Just use ordinary arithmetic to get the number of seconds.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Contrary to what you might think, Europe/London doesn't actually use Greenwich Mean Time. Not during this part of the year, anyway. If you want GMT, ask for TimeZone.getTimeZone("GMT") instead.

See here for a similar discussion, and a solution that avoids using Date and DateFormat entirely, instead using simple math as Paul suggests.
[ October 02, 2007: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Jim Yingst:
Contrary to what you might think, Europe/London doesn't actually use Greenwich Mean Time. Not during this part of the year, anyway. If you want GMT, ask for TimeZone.getTimeZone("GMT") instead.
The actual difference is that Britain was using daylight saving time on January 1, 1970!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Good point. Were they calling it British Summer Time back then? The mind boggles.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, they were.
 
Consider Paul's rocket mass heater.
 
subject: 10000 milliseconds showing as 01:00:10.000 - why ?
 
Similar Threads
epoch is wrong
Calendar() / Date() bug ???
Problem with day light savings in Simple Date Formatter
SQL dates, seconds since epoch and GMT/BST differences
Parsing Date/Time String - Urgent