【发布时间】:2011-01-04 13:16:24
【问题描述】:
我正在尝试将本地时区的日期转换为 GMT,我做了类似的事情
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String gmtStrDate = sdf.format(Calendar.getInstance().getTime());
System.out.println("GMT 1"+gmtStrDate);
Date gmtDate = sdf.parse(gmtStrDate);
System.out.println("GMT 2"+gmtDate);
我在 GMT tz 获得 GMT 1 o/p 但 GMT 2 o/p 再次更改为本地时区...谁能告诉我为什么?
为了在 GMT 中获得 GMT 2 o/p,我这样做了:
日历 = Calendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.setTime(gmtDate);
System.out.println("GMT 3 = "+calendar.getTime());
但格林威治标准时间 3o/p 仍然进入当地 tz。请就此提出建议。
【问题讨论】: