• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Getting current Time in Groovy

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am VERY new to Groovy, and am trying to get a current Time value. My code does execute, but I am not sure I am getting the correct value.
What I want to do is get the current Date/Time in UTC, which I understand should be roughly the same as GMT.
I am running this code on a machine that is in Eastern Standard time. So, assuming it is 5:00 PM here, which is (UTC-4 with DST), I would think that my method
should return 9:00 PM as the current time.
However, I get the value 5:00 PM returned. Maybe something in Groovy/Grails is switching the value to the current system time zone?
I am guessing that I must be missing something in the big picture here. Thanks for any advice!!!


Kim
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Still researching this and I realize that I may be attacking the problem the wrong way. When I do a Date now = new Date();, I wanted to make sure now was in UTC, which I now read is the default for the java.util.Date object.
So, as long as I make my Date objects myself, they are in UTC.

So, I guess my question is more in comparing dates, if I create Date now = new Date();

And then a user passes a String value to my program of "March 18, 2010 1:05 PM PST",

and I want to convert that String to a date and then find the difference between the two dates, How would I make sure I am not comparing apples to oranges ?

For example I want to say now - (Date value of String 1:05 PM PST) = some value.

I would want the calculation to return the same elapsed time if an equivalent PST or EST string was passed to the program .

Thanks, this is hurting my brain!
Kim
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Calendar class; it accepts timezones.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic