Why does parsing '23:00 PM' with SimpleDateFormat(“hh:mm aa”) return 11 a.m.?

前端 未结 6 2046
我寻月下人不归
我寻月下人不归 2020-12-09 19:30

Why does parsing \'23:00 PM\' with SimpleDateFormat(\"hh:mm aa\") return 11 a.m.?

6条回答
  •  孤城傲影
    2020-12-09 20:20

    Here are the formatting options specifed in the javadoc

    H     Hour in day (0-23)    
    k   Hour in day (1-24)  
    K   Hour in am/pm (0-11)    
    h   Hour in am/pm (1-12) 
    

    Notice that "h" would be for hours 1-12. If you want to handle 1-24, try "k". for 0-23 try "H". But I would not expect valid results if you are putting in impossible data.

提交回复
热议问题