| 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
|
 |
 |
|
|
subject: Need to specify the time as GMT while creating the date, JVM is on EST
|
|
|