Mar 12, 2017 02:39:00 "America/Chicago"
does not exist. When I set the date and time to this value it does not fail. The time gets set to Mar 12, 2017 03:39:00
an hour later. How can I be notified that this time does not exist. Here is how the time skips forward
01:59:59
3:00:00
As you can see 02:39:00
will never exist on this date.
Here is the code I am using
package com.company;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class Main {
public static void main(String[] args) {
ZoneId zoneId = ZoneId.of("America/Chicago");
ZonedDateTime dateTimeStart = ZonedDateTime.of(2017, 1, 1, 15, 39, 0, 0, ZoneId.of("America/Chicago"));
ZonedDateTime dateTimeStartUtc = dateTimeStart.withZoneSameInstant(ZoneOffset.UTC);
ZoneId zoneIdDst = ZoneId.of("America/Chicago");
ZonedDateTime dateTimeStartDst = ZonedDateTime.of(2017, 3, 12, 2, 39, 0, 0, ZoneId.of("America/Chicago"));
ZonedDateTime dateTimeStartUtcDst = dateTimeStart.withZoneSameInstant(ZoneOffset.UTC);
int y = 90;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…