Parsing an ISO 8601 date in Java8 when all fields (including separators, but not including years) are optional

前端 未结 4 1666
北海茫月
北海茫月 2021-01-15 06:26

I have a requirement for parsing ISO8601 formatted strings in Java with various levels of accuracy. Some examples of the string I need to parse are:

  • 2018
4条回答
  •  野的像风
    2021-01-15 06:32

    You can create a DateTimeFormatter with DateTimeFormatterBuilder, which has a method called parseDefaulting(). parseDefaulting() could set the default value if there is no matching.

提交回复
热议问题