converting a Date/Calendar object from local timezone to GMT ( date object)
i am having trouble converting date in local timezone to date in GMT
I have the following sample code.
package gmt;
import java.text.*;
import java.util.*;
public class Gmt {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Date d = new Date();
System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(sdf.format(d));
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(sdf.getTimeZone());
System.out.println(sdf.parse(sdf.format(d)));
}
catch(Exception e){
}
}
}
Output
Tue Jul 24 01:22:24 PDT 2007
07/24/2007 08:22:24 GMT
sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Tue Jul 24 01:22:24 PDT 2007
As we can see when i try parsing the string back to a Date object it gets converted to the local time again.
Please help me with this
Thanks

