How to parse a 1 or 2 digit hour string with Java?

后端 未结 5 782
走了就别回头了
走了就别回头了 2021-01-29 07:37

My parser may encounter \"2:37PM\" (parsed by \"H:mma\") or \"02:37PM\" (parsed by \"hh:mma\"). How can I parse both without resorting to a try-catch?

I receive an erro

5条回答
  •  庸人自扰
    2021-01-29 08:08

    You can create a string for the hours and have an if statement to check whether the hours is < 10 (single digit) then prepend "0".

提交回复
热议问题