• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Need to specify the time as GMT while creating the date, JVM is on EST

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I need to convert a time to GMT and store it in DB. I am able to do this. I need to retreive this time from DB at a later time and show it in the required time zone. How do I specify that a date is GMT time zone while creating the date? As per my knowledge, it takes the time zone where JVM is running. Here is the code snippet that I can convert from a given time to GMT, but how do I do the reverse, knowing that the time that I am getting is in GMT time format.

Converting to GMT
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("Time in GMT : " + sdf.format(date));

Converting from GMT to a specified timezone??
SimpleDateFormat sdf2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
sdf2.setTimeZone(TimeZone.getTimeZone("PST"));
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
// HOW DO I SPECIFY THE DATE AS GMT DATE. THIS IS TAKING AS JVM'S TIMEZONE.
cal.setTime(date);
System.out.println("Time in PST : " + sdf2.format(cal.getTime()));



Thanks
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic