ZoneRules Resolves Instant Offsets
Ask the zone rule table for the offset in force at an instant, whether daylight savings applies, and when the next clock change lands.
Code
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.zone.ZoneRules;
public class OffsetResolution {
public static void main(String[] args) {
ZoneRules rules = ZoneId.of("Europe/Paris").getRules();
Instant summer = Instant.parse("2026-07-01T12:00:00Z");
Instant winter = Instant.parse("2026-01-01T12:00:00Z");
// 同一规则表把时刻映射到唯一偏移:冬天 +01:00,夏天 +02:00
System.out.println("winter offset: " + rules.getOffset(winter));
System.out.println("summer offset: " + rules.getOffset(summer));
System.out.println("summer is DST: " + rules.isDaylightSavings(summer));
System.out.println("summer DST amount: " + rules.getDaylightSavings(summer));
// 下一次钟点跳变:间隙还是重叠由规则表给出
var transition = rules.nextTransition(winter);
System.out.println("next transition at: " + transition.getInstant());
System.out.println("gap? " + transition.isGap()
+ " duration: " + transition.getDuration());
System.out.println("offset " + transition.getOffsetBefore()
+ " -> " + transition.getOffsetAfter());
}
}What the code does
ZoneRules Resolves Instant Offsets keeps everything in the class OffsetResolution and the function main.
Caveats
- No lockfile entry, no version pinning — the file needs nothing beyond the runtime.
Applying it
The main signature reads public static void main(String[] args)
The run emits 7 labeled sections — winter offset:, summer offset:, summer is DST:, summer DST amount:, next transition at:, gap?, offset — one per step.
Statements that matter
ZoneRules rules = ZoneId.of("Europe/Paris").getRules();
Instant summer = Instant.parse("2026-07-01T12:00:00Z");
Instant winter = Instant.parse("2026-01-01T12:00:00Z");
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 ZoneRules Resolves Instant Offsets print when run?
- Run it as a complete program — the output lines carry labels such as `winter offset:`, `summer offset:`, `summer is DST:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.