How can I validate a local date time within daylight savings time?

前端 未结 2 1206
鱼传尺愫
鱼传尺愫 2020-12-11 01:34

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 0

2条回答
  •  醉梦人生
    2020-12-11 01:40

    Here a validation without throwing exceptions. You only need to ask the zone rules if a LocalDateTime is valid within a given timezone:

    public static boolean isValid(LocalDateTime ldt, ZoneId zoneId) {
        return !zoneId.getRules().getValidOffsets(ldt).isEmpty();
    }
    

提交回复
热议问题