How to parse ZonedDateTime with default zone?

后端 未结 2 1262
野的像风
野的像风 2020-12-09 17:52

How to parse ZoneDateTime from string that doesn\'t contain zone and others fields?

Here is test in Spock to reproduce:

imp         


        
2条回答
  •  春和景丽
    2020-12-09 18:30

    The formatter has a withZone() method that can be called to provide the missing time-zone.

    ZonedDateTime.parse(
        value,
        DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(ZoneId.systemDefault()))
    

    Bear in mind that there was a bug, so you need 8u20 or later for it to work fully.

提交回复
热议问题