• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

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
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic