请教一下,现在调用Date类生成的日期,在我的机器上默认是CST格式,请问怎么才能转换成GMT格式,谢谢。
import java.util.Date;
import java.text.SimpleDateFormat;
class ex71
{
public static void main(String args[ ])
{
Date nowTime=new Date();
System.out.println("现在的时间:"+nowTime);
SimpleDateFormat matter1=new SimpleDateFormat(" 'time':yyyy-MM-dd");
System.out.println("现在的时间:"+matter1.format(nowTime));
}
}
import java.util.Date;
import java.text.SimpleDateFormat;
class ex71
{
public static void main(String args[ ])
{
Date nowTime=new Date();
System.out.println("现在的时间:"+nowTime);
SimpleDateFormat matter1=new SimpleDateFormat(" 'time':yyyy-MM-dd");
System.out.println("现在的时间:"+matter1.format(nowTime));
}
}
System.out.println("现在的时间:" + nowTime);
SimpleDateFormat matter1 = new SimpleDateFormat("'time': yyyy-MM-dd HH:mm:ss z");
matter1.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("现在的时间:" + matter1.format(nowTime));
SimpleDateFormat matter1 = new SimpleDateFormat("'time': yyyy-MM-dd HH:mm:ss z");
System.out.println("现在的时间" + matter1.format(nowTime));
matter1.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("现在的时间" + matter1.format(nowTime));不知道你的为什么没有变,我的输出结果是:现在的时间time: 2007-08-23 09:42:54 CST
现在的时间time: 2007-08-23 01:42:54 GMT很明显地变掉了。
Date nowTime = new Date();
SimpleDateFormat matter1 = new SimpleDateFormat( " 'time ': yyyy-MM-dd HH:mm:ss z ");
System.out.println( "现在的时间 " + matter1.format(nowTime));
matter1.setTimeZone(TimeZone.getTimeZone( "CST"));
System.out.println( "现在的时间 " + matter1.format(nowTime));
我是GMT转成CST 应该是+8小时撒。
现在的时间 time : 2010-03-11 15:05:43 GMT
现在的时间 time : 2010-03-11 09:05:43 CST
最后输出又减8个小时
我人在中国,默认的是GMT 不知道怎么回事