How Java 8 time api selects an offset during a DST change period

In the Java 8-time API, you can create a LocalDateTime that falls on time overlap during DST time changes in the fall (Central European Time).

You can convert this to ZonedDateTime, which is an exact point in time using ZoneId.

Doing this does not actually resolve the ambiguity - there can still be two points in time that correspond to this LocalDateTime and this zone (but at different offsets).

How and why (reference greeting) does the Time API select a summer offset?

@Test
public void TimeSetOnDST() throws Exception {
    LocalDateTime time = LocalDateTime.of(2016, 10, 30, 2, 30); // in the DST time overlap
    ZonedDateTime of = ZonedDateTime.of(time, ZoneId.of("Europe/Zurich"));
    System.out.println(of); // 2016-10-30T02:30+02:00[Europe/Zurich]
    // But why not 2016-10-30T02:30+01:00[Europe/Zurich] ?
    // Is this just "by convention"?
}
+4
source share
1 answer

This is well described in javadoc :

-. , , . , "".

@JodaStephen, , withLaterOffsetAtOverlap.

+3

Source: https://habr.com/ru/post/1657470/


All Articles