【发布时间】:2013-06-24 20:09:59
【问题描述】:
kk:mm、HH:mm 和 hh:mm 格式有什么区别??
SimpleDateFormat broken = new SimpleDateFormat("kk:mm:ss");
broken.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
SimpleDateFormat working = new SimpleDateFormat("HH:mm:ss");
working.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
SimpleDateFormat working2 = new SimpleDateFormat("hh:mm:ss");
working.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
System.out.println(broken.format(epoch));
System.out.println(working.format(epoch));
System.out.println(working2.format(epoch));
打印:
24:00:00
00:00:00
05:30:00
【问题讨论】:
-
仅供参考,麻烦的旧日期时间类,如
java.util.Date、java.util.Calendar和java.text.SimpleTextFormat现在是 legacy,被 java.time 类取代。见Tutorial by Oracle。 -
您在
working上设置了两次时区,而在working2上没有设置任何时区。这可能是您的第三个结果不同的原因。