JDK8: unable to parse LocalTime

后端 未结 4 1324
北荒
北荒 2020-12-17 10:16

I managed to parse a String to a LocalDate object:

DateTimeFormatter f1=DateTimeFormatter.ofPattern(\"dd MM yyyy\");
LocalDate d=Lo         


        
4条回答
  •  别那么骄傲
    2020-12-17 10:51

    You need to use capital HH in the pattern

    DateTimeFormatter f2=DateTimeFormatter.ofPattern("HH mm");
    

    or do this, for clock-hour-of-am-pm you need to specify it.

    This should also work

    DateTimeFormatter f2=DateTimeFormatter.ofPattern("hh mm a");
    LocalTime t=LocalTime.parse("11 08 AM",f2); //exception here
    

提交回复
热议问题