• 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

Greenwich mean time

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought this would be rather simple to do but its really thrown me. My problem is that I've got an input calendar to my function that contains the Greenwich Mean Time (GMT). I have to test if this time is more than 10 minutes earlier than my current time, so I want to get my curent time expressed as GMT and then just make the comparison. My problem is that I'm always getting my local time and can't seem to convert it to either a Calendar or Date value expressed in GMT. I can format it in GMT using the DateFormat function but that's only useful for converting the result to a string. Thanks, Joe
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API docs for Date say you'll have to get a Calendar object and call get(Calendar.ZONE_OFFSET) and get(Calendar.DST_OFFSET) on it, and do the arithmetic yourself. The Calendar class looks complicated. Enjoy.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's GMT you want, no Calendar should be necessary. System.currentTimeMillis() gives you the number of milliseconds elapsed since Jan 1, 1970 GMT. It sounds like you already have your GMT input converted to a Date, so you can use Date's getTime() method to get the total milliseconds since 1/1/1970 GMT for you input, and then check to see if the difference is greater than 600000 milliseconds (10 min).
 
Joe Guzzardo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, thanks Jim. I realized later while on the way home from work that what you suggested would work in my case. I liked your suggestion to just get the difference between the two times and then test if it exceeds 600000. I was taking my local GMT and subtracting 60000 from it and then doing the compare, the net result is the same but your suggestion is a little cleaner.
Thanks again Jim.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic