gpt4 book ai didi

java - java HH :mm and hh:mm on SimpleDateFormat之间的区别

转载 作者:IT老高 更新时间:2023-10-28 20:36:07 28 4
gpt4 key购买 nike

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

最佳答案

kk: (01-24) 看起来像 01, 02..24。

HH:(00-23) 看起来像 00, 01..23。

hh:(上午/下午的 01-12)看起来像 01、02..12。

所以最后的打印输出 (working2) 有点奇怪。应该说 12:00:00(编辑:如果你设置 working2 时区和格式,(正如 kdagli 指出的那样)你不是)

关于java - java HH :mm and hh:mm on SimpleDateFormat之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17341214/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com