Can't parse String to LocalDate (Java 8)

后端 未结 2 505
半阙折子戏
半阙折子戏 2020-11-30 06:20

My input is a String representation of a date in the format \"01-07-2015\" for July 1, 2015. I\'m trying to parse this into a java.time.LocalDate variable:

2条回答
  •  生来不讨喜
    2020-11-30 07:03

    For year you have to use the lowercase y:

    final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy");
    

    Uppercase Y is used for weekyear. See the javadoc of DateTimeFormatter for more details.

提交回复
热议问题