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:0000:00:0005:30:00
3 回答

素胚勾勒不出你
TA貢獻1827條經驗 獲得超9個贊
kk:(01-24)看起來像01,02..24。
HH:(00-23)看起來像00,01..23。
hh:(AM / PM中的01-12)看起來像01,02..12。
因此最后一個打印輸出(working2)有點奇怪。它應該說12:00:00(編輯:如果您正在設置working2時區和格式,那不是(如kdagli指出的那樣))

大話西游666
TA貢獻1817條經驗 獲得超14個贊
實際上,最后一個并不奇怪。代碼設置的是工作時區,而不是工作時區2。
SimpleDateFormat working2 = new SimpleDateFormat("hh:mm:ss"); 工作中.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
kk從1到24,HH從0到23,hh從1到12(AM / PM)。
修復此錯誤可以得到:
24:00:00
00:00:00
01:00:00
添加回答
舉報
0/150
提交
取消