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

后端 未结 5 727
走了就别回头了
走了就别回头了 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:04

    To my surprise, it looks like the answer was formatter "h:mma", which actually discerns correctly between one- and two-digit hour specifications and even catches technically dubious times like "02:38 PM" (which should probably not have a leading 0, but tell it to my data sources...)

提交回复
热议问题