ZoneId Rules Resolve Instant Offsets
ZoneRules resolve any instant to the real offset of a zone; fixed IDs like UTC+01:00 normalize to ZoneOffset, and zones come from the JDK's bundled IANA tzdb.
Code
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
public class ZoneLookups {
public static void main(String[] args) {
ZoneId zone = ZoneId.of("Asia/Shanghai");
Instant now = Instant.parse("2026-11-21T00:00:00Z");
// ZoneRules resolve any instant to the zone's real offset at that moment
System.out.println("offset=" + zone.getRules().getOffset(now));
// build a fixed offset by hand: hours plus minutes
ZoneOffset custom = ZoneOffset.ofHoursMinutes(5, 30);
System.out.println("custom=" + custom);
// fixed IDs like UTC+01:00 normalize to the ZoneOffset itself
System.out.println("normalized=" + ZoneId.of("UTC+01:00").normalized());
// the zone list comes from the JDK's bundled IANA tzdb copy: the count varies with JDK updates, not OS tzdata
System.out.println("zones registered: " + ZoneId.getAvailableZoneIds().size());
}
}What the demo resolves
Asia/Shanghai asked about the instant 2026-11-21T00:00:00Z answers +08:00. ZoneRules.getOffset resolves any instant to the offset actually in force at that moment, including DST boundaries elsewhere in the year.
Fixed offsets need no zone database: ofHoursMinutes(5, 30) builds +05:30 directly, and the ID UTC+01:00 normalizes to the ZoneOffset itself. The final line counts getAvailableZoneIds: zones ship inside the JDK’s bundled IANA tzdb copy, so the count changes with JDK updates, not with the operating system’s tzdata.
Points worth noting
- normalized() is what collapses UTC-style IDs onto real ZoneOffset instances.
- Following the OS tzdb would require a custom ZoneRulesProvider.
Interactive Tools for This Topic
FAQ
- Where does the zone list come from?
- From the IANA tzdb copy bundled inside the JDK (lib/tzdb.dat); the count varies with JDK releases. Upgrading OS tzdata does not change java.time unless a custom ZoneRulesProvider is installed.
Report a problem with this exampleOpens a pre-filled issue on GitHub.