• 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

Help needed on using dates and calendar

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to convert "2005-06-21 03:06:25,EST" to GMT equivalent in the same format (like "2005-06-21 011:06:25,GMT"). Can anybody tell me correct way to implement this?
Is it required for us to know the GMT offset and other considerations like Daylight Savings for convertion ? OR it can be handled automatically in Java?
I am trying in following way.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd,hh:mm:ss");
Date firstDate = sdf.parse("2005-06-21 03:06:25");
I am not clear how to proceed..using Calendar/TimeZone or manually add the GMT offset to this date.
One problem is , even if i set the timezone as GMT for calendar, if i do getTime(), it always says IST. why?

Please clarify.

Thanks in advance
Naveen Hegde
Bangalore
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use something like

Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
formatter .setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("Current GMT time = " + formatter.format(now));


Use the formatter instance to parse of to format the current time after setting the TimeZone to GMT.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic