当应用 GMT 转换时,我尝试将时间转换回默认值。
public static void main(String[] args) {
// initial time is: 14:43
Calendar cal = Calendar.getInstance();
cal.set(2013, 8, 1, 14, 43, 0);
// configuring formatter to apply GMT rule.. now I would have: 18:43 (+4 hours shift)
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
// but then I want rest my GMT shift back to initial time format
String startDate = formatter.format(new Date(cal.getTimeInMillis() + TimeZone.getDefault().getRawOffset()));
System.out.println(startDate);
}
它打印:2013/09/01 13:43:00
但我期望:2013/09/01 14:43:00
方法是什么?