• 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

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point. Were they calling it British Summer Time back then? The mind boggles.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, they were.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic