Failed to parse single digit hour and lowercase am-pm of day into Java 8 LocalTime

前端 未结 6 1987
借酒劲吻你
借酒劲吻你 2021-01-05 10:50

When I try to run the following code:

LocalTime test = LocalTime.parse(\"8:00am\", DateTimeFormatter.ofPattern(\"hh:mma\"));

I get this:

6条回答
  •  粉色の甜心
    2021-01-05 11:22

    You need to capitalize to AM and add a leading zero in front of the 8.

    LocalTime lt=LocalTime.parse("08:00AM",DateTimeFormatter.ofPattern("hh:mma"));
    

提交回复
热议问题