aspose file tools
The moose likes Java in General and the fly likes Need to specify the time as GMT while creating the date, JVM is on EST Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Need to specify the time as GMT while creating the date, JVM is on EST" Watch "Need to specify the time as GMT while creating the date, JVM is on EST" New topic
Author

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

Sunjay Kumar
Greenhorn

Joined: Sep 07, 2005
Posts: 1
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 agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Need to specify the time as GMT while creating the date, JVM is on EST
 
Similar Threads
Convert Local time to UTC and vice versa
TimeZone Conversion
Need Help on Time conversion.
Timezone offset to Timezone ID conversion
Calendar.set(HOUR_OF_DAY, 1) confusion