SimpleDateFormat返回1小时为什么?

时间:2014-07-26 12:52:10

标签: android parsing date simpledateformat

我有SimpleDateFormat。

Date vrcTime;
SimpleDateFormat vrcCurrentTimeTextValue;
vrcTime.setTime (0);
vrcTimeFormat = new SimpleDateFormat ("HH:mm:ss");
vrcCurrentTimeTextValue =  vrcTimeFormat.format (vrcTime);

为什么即使时间为0,我的SimpleDateFormat也会返回1小时?

1 个答案:

答案 0 :(得分:1)

您居住在GMT + 1时区,除非您指定另一个时区,否则您的格式化程序将选择您当前的格式化程序,因此它将0小时视为GMT,而您在GMT + 1时则输出1小时。 所以添加

vrcTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

即。将代码重写为

Date vrcTime;
SimpleDateFormat vrcCurrentTimeTextValue;
vrcTime.setTime (0);
vrcTimeFormat = new SimpleDateFormat ("HH:mm:ss");
vrcTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
vrcCurrentTimeTextValue =  vrcTimeFormat.format (vrcTime);
相关问题