本文介紹了SimpleDateFormat 上的 java HH:mm 和 hh:mm 之間的區(qū)別的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
kk:mm、HH:mm 和 hh:mm 格式有什么區(qū)別??
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
) 有點(diǎn)奇怪.應(yīng)該說 12:00:00(如果你設(shè)置 working2
時(shí)區(qū)和格式,(正如 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)
這篇關(guān)于SimpleDateFormat 上的 java HH:mm 和 hh:mm 之間的區(qū)別的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!