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.
Code
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
Duration ConverterConvert between human durations like 1w2d3h45m and total seconds, hours, and minutes with negative support.Duration HumanizerTurn a number of seconds into a readable duration such as 1 day, 2 hours, 3 minutes, and show the equivalent in minutes and hours.ISO 8601 Duration ParserParse ISO 8601 durations like PT1H30M into year, month, week, day, and time components with exact or approximate total seconds.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
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.
Report a problem with this exampleOpens a pre-filled issue on GitHub.