ZonedDateTime DST Gap And Overlap

DST gaps shift forward with atZone and overlaps default to the earlier offset; withLaterOffsetAtOverlap pins the other side of a repeated wall-clock time.

JavaData Integrity

Code

snippet
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class DstGapOverlap {

    static final ZoneId NEW_YORK = ZoneId.of("America/New_York");

    public static void main(String[] args) {
        // DST 春季跳变:2026-03-08 02:30 在纽约不存在,atZone 向后平移一个时差
        ZonedDateTime inGap = LocalDateTime.of(2026, 3, 8, 2, 30).atZone(NEW_YORK);
        System.out.println("gap -> hour " + inGap.getHour() + ", offset " + inGap.getOffset());

        // DST 秋季重叠:2026-11-01 01:30 出现两次,默认取较早的偏移
        ZonedDateTime overlap = LocalDateTime.of(2026, 11, 1, 1, 30).atZone(NEW_YORK);
        System.out.println("overlap default: " + overlap.getOffset());
        System.out.println("overlap later:   " + overlap.withLaterOffsetAtOverlap().getOffset());
    }
}

How it works

ZonedDateTime DST Gap And Overlap reduces to the class DstGapOverlap and the function main.

Putting it to use

Running the file prints labeled results such as gap -> hour, overlap default:, overlap later: — each operation’s effect is visible in the output.

Core lines

ZonedDateTime overlap = LocalDateTime.of(2026, 11, 1, 1, 30).atZone(NEW_YORK);
ZonedDateTime inGap = LocalDateTime.of(2026, 3, 8, 2, 30).atZone(NEW_YORK);
static final ZoneId NEW_YORK = ZoneId.of("America/New_York");

Interactive Tools for This Topic

FAQ

What does ZonedDateTime DST Gap And Overlap print when run?
No setup needed: run the file and look for labeled lines like `gap -> hour`, `overlap default:`, `overlap later:` in the output.