Difference between java HH:mm and hh:mm on SimpleDateFormat(SimpleDateFormat 上的 java HH:mm 和 hh:mm 之间的区别)
问题描述
kk:mm、HH:mm 和 hh:mm 格式有什么区别??
Whats the difference between kk:mm, HH:mm and hh:mm formats ??
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
推荐答案
kk: (01-24) 看起来像 01, 02..24.
kk: (01-24) will look like 01, 02..24.
HH:(00-23) 看起来像 00, 01..23.
HH:(00-23) will look like 00, 01..23.
hh:(上午/下午的 01-12)看起来像 01、02..12.
hh:(01-12 in AM/PM) will look like 01, 02..12.
所以最后的打印输出 (working2) 有点奇怪.应该说 12:00:00(如果你设置 working2 时区和格式,(正如 kdagli 指出的那样)你不是)
so the last printout (working2) is a bit weird. It should say 12:00:00
(edit: if you were setting the working2 timezone and format, which (as kdagli pointed out) you are not)
这篇关于SimpleDateFormat 上的 java HH:mm 和 hh:mm 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SimpleDateFormat 上的 java HH:mm 和 hh:mm 之间的区别
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
