我用格式为“HH:mm”的字符串解析时间为java.text.SimpleDateFormat
。例如10:30
或22:10
SimpleDateFormat解析不正确的时间
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
Date parsed = formatter.parse((String) value);
格式化时区是为我的设备(莫斯科时间+04:00),默认的时区。时间字符串是10:30
和 解析后,我预计在莫斯科时区10:30 01/01/1970
,但取而代之的是09:30 01/01/1970
。我做错了什么?为什么我得到这种行为?
'日期'是非常不可靠的。使用[日历](http://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html),或者甚至更好[乔达时间](http://joda-time.sourceforge。净/)来处理日期 – Keppil 2012-07-17 07:35:15
@Keppil在这种情况下,这是正确的,但你说得对,Joda时间是一个更好的选择。 – 2012-07-17 07:36:31
@PeterLawrey:是的,对于这个特殊情况没有很好的答案,但我想我会提及它希望让OP避免很多未来的麻烦。 – Keppil 2012-07-17 07:40:42