ZonedDateTime toString compatability with ISO 8601

前端 未结 4 2278
走了就别回头了
走了就别回头了 2021-02-18 23:43

I am trying to ensure that calling toString() on my ZonedDateTime Object will comply with ISO-8601 format.

The documentation for the toSt

4条回答
  •  别那么骄傲
    2021-02-19 00:10

    As per the official documentation:

    Obtaining the offset for an instant is simple, as there is exactly one valid offset for each instant. By contrast, obtaining the offset for a local date-time is not straightforward. There are three cases:

    • Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.
    • Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.
    • Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.

    So the 2nd and 3rd case are the situations where toString() will not be ISO-8601 compliant.

提交回复
热议问题