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

[1168 byte] By [pratikshah83a] at [2007-11-27 11:31:18]
# 1

Please don't cross post - http://forum.java.sun.com/thread.jspa?threadID=5198277&tstart=0

sabre150a at 2007-7-29 16:38:56 > top of Java-index,Java Essentials,Training...