• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!