DateTimeParseException: Text could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor

后端 未结 1 2138
一向
一向 2021-02-07 10:12
LocalDateTime.parse(\"2017-02-02 08:59:12\", DateTimeFormatter.ofPattern(\"yyyy-MM-dd hh:mm:ss\"));

It prints error:

java.time.format         


        
相关标签:
1条回答
  • 2021-02-07 10:34

    I can only reproduce the exception you get when I try to parse to a LocalDateTime, so I assume that's what you want.

    Your mistake is using hh (clock-hour-of-am-pm) instead of HH (hour-of-day). This works:

    LocalDateTime ldt = LocalDateTime.parse("2017-02-02 08:59:12", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    System.out.println(ldt);
    

    And prints:

    2017-02-02T08:59:12
    
    0 讨论(0)
提交回复
热议问题