Java DateTimeFormatterBuilder with optional pattern results in DateTimeParseException

前端 未结 4 1359
傲寒
傲寒 2021-01-19 13:30

Goal

Provide a flexible parser for LocalDate instances that can handle input in one of the following formats:

  • yyyy
  • yyyyMM
  • yyyyMMdd<
4条回答
  •  一整个雨季
    2021-01-19 14:22

    In this part of the code you already set a value for month and day .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) Then you're trying to pass an input for month and year in your code System.out.println(parser.parse("201411", LocalDate::from)); That you already set.

提交回复
热议问题