This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Sheriff
Posts: 23692
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23692
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. Were they calling it British Summer Time back then? The mind boggles.
 
Paul Clapham
Sheriff
Posts: 23692
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, they were.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!