In Java 8 time API, you can create a LocalDateTime which falls in the overlap of time during the DST time change in autumn (Central European Time).
You can convert this to a ZonedDateTime which represents a precise moment in time using a ZoneId.
Doing this does not actually resolve the ambiguity - there could still be two moments in time which correspond to this LocalDateTime and this Zone (but at different offsets).
How and why (reference welcome) does the time API choose the 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"?
}
It's well documented in the javadoc:
In most cases, there is only one valid offset for a local date-time. In the case of an overlap, when clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer".
As described in the comments by @JodaStephen, if you want to choose the other available offset, you can use the withLaterOffsetAtOverlap
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With