Date & Time ·
‹ Previous Next ›
⏱ 5 min read Modified: 2026-12-02

ZonedDateTime in Java: ZoneId, Time Zones and Daylight Saving Time

A weekly call is booked for 10:00 New York time, and a colleague in Berlin is used to joining at 16:00. But from 9 to 23 March 2026 the call starts at 15:00 Berlin time: the US switched to daylight saving time on 8 March, Europe not until 29 March. Code that hard-codes “plus 6 hours” is wrong for three weeks in spring and one more week in autumn.

ZonedDateTime in Java (java.time.ZonedDateTime) is an immutable, thread-safe class that stores a date and time together with a time zone: a LocalDateTime + a zone identifier (ZoneId) + the offset from UTC in effect at that moment (ZoneOffset). A single object pins down an exact instant on the timeline and knows the clock-change rules of its region. For example, ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, ZoneId.of("Europe/Berlin")) prints as 2026-07-15T10:00+02:00[Europe/Berlin].

ZoneId and ZoneOffset: region vs offset

ZoneId is the time zone type in java.time, and it comes in two kinds: a region (ZoneRegion, e.g. Europe/Moscow) with its full history and clock-change rules, and a fixed offset (ZoneOffset, e.g. +03:00) that never changes. Both extend ZoneId, so either one works wherever a zone is expected. You get a zone from ZoneId.of(String).

What you get back depends on the shape of the string:

String passed to ZoneId.of() Result Comment
"Europe/Moscow" ZoneRegion Europe/Moscow IANA region: history and clock-change rules
"+03:00", "+3" ZoneOffset +03:00 Fixed offset, no rules
"Z" ZoneOffset Z Same as ZoneOffset.UTC
"UTC" ZoneRegion UTC A region, not an offset; normalized() → Z
"GMT+3" ZoneRegion GMT+03:00 Prefix + offset; normalized() → +03:00
"UTC+05:30" ZoneRegion UTC+05:30 Same as with GMT; normalized() → +05:30
"PST", "MSK" ZoneRulesException: Unknown time-zone ID Short names are not accepted directly
"Europe/Moskow", "europe/moscow" ZoneRulesException: Unknown time-zone ID A typo or wrong case fails immediately

Short names like PST only work through the alias map: ZoneId.of("PST", ZoneId.SHORT_IDS) returns America/Los_Angeles. The same map gives a surprising answer for "EST": America/Panama, a zone with no daylight saving time. If you meant New York, you will be an hour off all summer. Write the full region ID instead.

import java.time.ZoneId;
import java.time.ZoneOffset;

public class ZoneIdExample {
    public static void main(String[] args) {
        System.out.println(ZoneId.of("PST", ZoneId.SHORT_IDS));   // America/Los_Angeles
        System.out.println(ZoneId.of("EST", ZoneId.SHORT_IDS));   // America/Panama
        System.out.println(ZoneId.of("UTC").normalized());        // Z
        System.out.println(ZoneId.of("GMT+3").normalized());      // +03:00
        System.out.println(ZoneId.getAvailableZoneIds().size());  // 604 (JDK 25.0.3, tzdb 2026a)

        // Old and new spelling of Kyiv - both zones work, the rules are identical
        System.out.println(ZoneId.of("Europe/Kiev").getRules()
                .equals(ZoneId.of("Europe/Kyiv").getRules()));    // true

        System.out.println(ZoneOffset.of("+05:30"));              // +05:30
        System.out.println(ZoneOffset.ofHoursMinutes(5, 30));     // +05:30
        ZoneOffset.ofHours(19);
        // DateTimeException: Zone offset hours not in valid range:
        // value 19 is not in the range -18 to 18

        ZoneId.of("MSK");
        // ZoneRulesException: Unknown time-zone ID: MSK
    }
}

The full list of IDs comes from ZoneId.getAvailableZoneIds(). Its size depends on the time zone database bundled with the JDK: 604 on JDK 25.0.3 (tzdb 2026a), 603 on a JDK 21 build with tzdb 2023c. A ZoneOffset must lie between minus 18 and plus 18 hours.

ZoneId.systemDefault() returns the JVM's default zone. It usually differs between your laptop and the server, so don't rely on it implicitly in server code — more on that in LocalDateTime: converting to Instant and ZonedDateTime.

Creating a ZonedDateTime: of(), atZone(), ofInstant(), parse()

A ZonedDateTime is created with factory methods: ZonedDateTime.of(...) from individual fields, of(LocalDate, LocalTime, ZoneId), localDateTime.atZone(zone), ZonedDateTime.ofInstant(instant, zone) from an instant, now(zone) for the current time, and parse() from an ISO string such as 2026-07-15T10:00+02:00[Europe/Berlin]. The class has no public constructor.

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CreateZonedDateTimeExample {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");

        ZonedDateTime z1 = ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, berlin);
        ZonedDateTime z2 = ZonedDateTime.of(LocalDate.of(2026, 7, 15), LocalTime.of(10, 0), berlin);
        ZonedDateTime z3 = LocalDateTime.of(2026, 7, 15, 10, 0).atZone(berlin);
        ZonedDateTime z4 = ZonedDateTime.ofInstant(Instant.parse("2026-07-15T08:00:00Z"), berlin);
        ZonedDateTime z5 = ZonedDateTime.parse("2026-07-15T10:00+02:00[Europe/Berlin]");

        System.out.println(z1);
        System.out.println(z2);
        System.out.println(z3);
        System.out.println(z4);
        System.out.println(z5);
    }
}
2026-07-15T10:00+02:00[Europe/Berlin]
2026-07-15T10:00+02:00[Europe/Berlin]
2026-07-15T10:00+02:00[Europe/Berlin]
2026-07-15T10:00+02:00[Europe/Berlin]
2026-07-15T10:00+02:00[Europe/Berlin]

Five routes, one and the same object. ofInstant() goes the other way round: 08:00 UTC in summer is 10:00 in Berlin. instant.atZone(zone) does the same thing and is covered in the Instant lesson. For the current time in a zone, call ZonedDateTime.now(ZoneId.of("Europe/Berlin")); now() and swapping the clock with Clock are explained in Java Date and Time API.

parse() has three non-obvious cases. A string without a bracketed zone still parses, but the zone becomes a bare offset and the result has no clock-change rules. If the offset and the zone in the string contradict each other, the offset is treated as the truth about the instant, and the local time is recalculated. A string with no offset at all does not parse:

ZonedDateTime.parse("2026-07-15T10:00:00+02:00");
// 2026-07-15T10:00+02:00          - zone is a ZoneOffset, no DST rules

ZonedDateTime.parse("2026-07-15T10:00+05:00[Europe/Berlin]");
// 2026-07-15T07:00+02:00[Europe/Berlin]  - 10:00 at +05:00 = 07:00 in Berlin

ZonedDateTime.parse("2026-07-15T10:00");
// DateTimeParseException: Text '2026-07-15T10:00' could not be parsed at index 16

A custom pattern without a zone fails the same way:

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

ZonedDateTime.parse("2026-07-15 10:00", f);
// DateTimeParseException: Text '2026-07-15 10:00' could not be parsed:
// Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2026-07-15T10:00
// of type java.time.format.Parsed

// Fix 1: give the formatter a zone
ZonedDateTime a = ZonedDateTime.parse("2026-07-15 10:00", f.withZone(ZoneId.of("Europe/Berlin")));
// Fix 2: parse as LocalDateTime and attach the zone
ZonedDateTime b = LocalDateTime.parse("2026-07-15 10:00", f).atZone(ZoneId.of("Europe/Berlin"));

Both fixes produce 2026-07-15T10:00+02:00[Europe/Berlin]. Pattern letters for zones and offsets (VV, z, XXX, O) are covered in DateTimeFormatter: time zones in patterns.

Reading fields: zone, offset, date and time

Besides the usual date and time getters (getYear(), getHour(), getDayOfWeek() and so on), ZonedDateTime has getZone() for the region, getOffset() for the offset in effect on that particular date, and conversion methods: toLocalDateTime(), toLocalDate(), toInstant(), toOffsetDateTime().

ZonedDateTime z = ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, ZoneId.of("Europe/Berlin"));

System.out.println(z.getZone());            // Europe/Berlin
System.out.println(z.getOffset());          // +02:00
System.out.println(z.toLocalDateTime());    // 2026-07-15T10:00
System.out.println(z.toLocalDate());        // 2026-07-15
System.out.println(z.getDayOfWeek());       // WEDNESDAY
System.out.println(z.toInstant());          // 2026-07-15T08:00:00Z
System.out.println(z.toOffsetDateTime());   // 2026-07-15T10:00+02:00

Watch getOffset(): for the same zone in January it returns +01:00. The offset belongs to a specific instant, not to the zone.

Converting to another time zone: withZoneSameInstant()

To convert a time to another time zone in Java, call withZoneSameInstant(zone): the instant stays the same, only the wall-clock reading changes. withZoneSameLocal(zone) does the opposite — it keeps 10:00 on the clock but moves it to another zone, which gives you a different instant. For converting between cities you almost always want the first one.

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ConvertZoneExample {
    public static void main(String[] args) {
        ZonedDateTime ny = ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, ZoneId.of("America/New_York"));

        System.out.println(ny);
        System.out.println(ny.withZoneSameInstant(ZoneId.of("Europe/Berlin")));
        System.out.println(ny.withZoneSameInstant(ZoneId.of("Asia/Tokyo")));
        System.out.println(ny.withZoneSameInstant(ZoneId.of("Asia/Kolkata")));
        System.out.println(ny.withZoneSameLocal(ZoneId.of("Europe/Berlin")));
    }
}
2026-07-15T10:00-04:00[America/New_York]
2026-07-15T16:00+02:00[Europe/Berlin]
2026-07-15T23:00+09:00[Asia/Tokyo]
2026-07-15T19:30+05:30[Asia/Kolkata]
2026-07-15T10:00+02:00[Europe/Berlin]

India runs on +05:30, hence 19:30 rather than a whole hour. The last line is a different instant altogether: 10:00 in Berlin happens 6 hours before 10:00 in New York.

Method What it keeps What changes When to use it
withZoneSameInstant(zone) The instant (same toInstant()) Wall-clock date and time, offset “What time is it in Tokyo when it's 10:00 in New York?”
withZoneSameLocal(zone) Wall-clock date and time The instant Fixing a zone that was set by mistake; “10:00 local time in every office”

Back to the call from the opening. Five Mondays in a row, 10:00 New York time:

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class MeetingExample {
    public static void main(String[] args) {
        ZoneId newYork = ZoneId.of("America/New_York");
        ZoneId berlin = ZoneId.of("Europe/Berlin");

        for (int week = 0; week < 5; week++) {
            LocalDate date = LocalDate.of(2026, 3, 2).plusWeeks(week);
            ZonedDateTime call = ZonedDateTime.of(date, LocalTime.of(10, 0), newYork);
            ZonedDateTime inBerlin = call.withZoneSameInstant(berlin);
            System.out.println(date + " " + inBerlin.toLocalTime());
        }
    }
}
2026-03-02 16:00
2026-03-09 15:00
2026-03-16 15:00
2026-03-23 15:00
2026-03-30 16:00

For three weeks the gap between the cities is 5 hours, not 6. Code that stores regions instead of numbers handles this without a single if.

Daylight saving time in Java: gaps and overlaps

When clocks spring forward for daylight saving time, a slice of local time never exists — that's a gap. When they fall back, a slice of local time happens twice — that's an overlap. ZonedDateTime handles both automatically: a non-existent time is pushed forward, and an ambiguous one gets the earlier (summer) offset.

Dates used in the examples, all 2026: Europe changes clocks on 29 March (02:00 → 03:00, gap) and 25 October (03:00 → 02:00, overlap); the US on 8 March and 1 November. The next transitions after December 2026 are 28 March 2027 in Berlin and 14 March 2027 in New York.

Gap: 02:30 on 29 March does not exist in Berlin

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

public class GapExample {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");

        System.out.println(LocalDateTime.of(2026, 3, 29, 2, 30).atZone(berlin));
        System.out.println(ZonedDateTime.of(2026, 3, 29, 1, 59, 0, 0, berlin).plusMinutes(1));
        System.out.println(ZonedDateTime.of(2026, 3, 28, 2, 30, 0, 0, berlin).plusDays(1));
        System.out.println(ZonedDateTime.of(2026, 3, 29, 1, 30, 0, 0, berlin).withHour(2));
    }
}
2026-03-29T03:30+02:00[Europe/Berlin]
2026-03-29T03:00+02:00[Europe/Berlin]
2026-03-29T03:30+02:00[Europe/Berlin]
2026-03-29T03:30+02:00[Europe/Berlin]

The non-existent 02:30 is shifted forward by the length of the gap (one hour) and becomes 03:30. Every path that can land in the gap behaves this way: atZone(), plusDays(), withHour(). And one minute after 01:59 is 03:00. The atZone() case with 2024 dates is also shown in LocalDateTime vs Instant.

If a silent shift is not acceptable — say, a user typed in a time that doesn't exist — use ofStrict(). It checks that the “local time + offset” pair is valid in the zone:

ZonedDateTime.ofStrict(LocalDateTime.of(2026, 3, 29, 2, 30), ZoneOffset.ofHours(1), ZoneId.of("Europe/Berlin"));
// DateTimeException: LocalDateTime '2026-03-29T02:30' does not exist in zone 'Europe/Berlin'
// due to a gap in the local time-line, typically caused by daylight savings

Overlap: 02:30 on 25 October happens twice in Berlin

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

public class OverlapExample {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");
        LocalDateTime ldt = LocalDateTime.of(2026, 10, 25, 2, 30);

        ZonedDateTime early = ldt.atZone(berlin);
        ZonedDateTime late = early.withLaterOffsetAtOverlap();
        System.out.println(early);
        System.out.println(late);
        System.out.println(late.withEarlierOffsetAtOverlap());
        System.out.println(Duration.between(early, late));
        System.out.println(late.isAfter(early) + " " + late.equals(early));

        // The preferred offset is used only if it is valid
        System.out.println(ZonedDateTime.ofLocal(ldt, berlin, ZoneOffset.ofHours(1)));
        System.out.println(ZonedDateTime.ofLocal(ldt, berlin, ZoneOffset.ofHours(5)));

        // 30-minute steps through the overlap
        ZonedDateTime t = ZonedDateTime.of(2026, 10, 25, 1, 30, 0, 0, berlin);
        for (int i = 0; i < 4; i++) {
            System.out.println(t);
            t = t.plusMinutes(30);
        }

        // Starting from an Instant, there is no ambiguity
        System.out.println(Instant.parse("2026-10-25T00:30:00Z").atZone(berlin));
        System.out.println(Instant.parse("2026-10-25T01:30:00Z").atZone(berlin));
    }
}
2026-10-25T02:30+02:00[Europe/Berlin]
2026-10-25T02:30+01:00[Europe/Berlin]
2026-10-25T02:30+02:00[Europe/Berlin]
PT1H
true false
2026-10-25T02:30+01:00[Europe/Berlin]
2026-10-25T02:30+02:00[Europe/Berlin]
2026-10-25T01:30+02:00[Europe/Berlin]
2026-10-25T02:00+02:00[Europe/Berlin]
2026-10-25T02:30+02:00[Europe/Berlin]
2026-10-25T02:00+01:00[Europe/Berlin]
2026-10-25T02:30+02:00[Europe/Berlin]
2026-10-25T02:30+01:00[Europe/Berlin]

By default you get the earlier, summer offset +02:00. Two objects showing the same 02:30 are an hour apart. The loop shows the clock rolling back: after 02:30+02:00 comes 02:00 again, this time at +01:00. And if your source data is instants (Instant), the question “which of the two 02:30s?” never comes up.

Checking a time in advance

ZoneRules.getValidOffsets(localDateTime) returns the list of valid offsets: an empty list means a gap, two elements mean an overlap, one element means an ordinary time. getTransition(localDateTime) returns the transition itself, or null.

ZoneRules rules = ZoneId.of("Europe/Berlin").getRules();

System.out.println(rules.getValidOffsets(LocalDateTime.of(2026, 10, 25, 2, 30))); // [+02:00, +01:00]
System.out.println(rules.getValidOffsets(LocalDateTime.of(2026, 3, 29, 2, 30)));  // []
System.out.println(rules.getValidOffsets(LocalDateTime.of(2026, 7, 15, 10, 0)));  // [+02:00]

System.out.println(rules.getTransition(LocalDateTime.of(2026, 3, 29, 2, 30)));
// Transition[Gap at 2026-03-29T02:00+01:00 to +02:00]
System.out.println(rules.getTransition(LocalDateTime.of(2026, 10, 25, 2, 30)));
// Transition[Overlap at 2026-10-25T03:00+02:00 to +01:00]
System.out.println(rules.getTransition(LocalDateTime.of(2026, 7, 15, 10, 0)));    // null
Situation getValidOffsets().size() What atZone() / of() do How to choose explicitly
Ordinary time 1 Use the only offset Not needed
Gap (clocks forward) 0 Shift the time forward by the gap length ofStrict() — exception instead of a shift
Overlap (clocks back) 2 Use the earlier (summer) offset withLaterOffsetAtOverlap(), withEarlierOffsetAtOverlap(), ofLocal(ldt, zone, preferredOffset)

Days that don't start at 00:00

What does this code print? Some zones change clocks exactly at midnight, so on that day 00:00 simply doesn't exist:

System.out.println(LocalDate.of(2026, 3, 8).atStartOfDay(ZoneId.of("America/Havana")));
// 2026-03-08T01:00-04:00[America/Havana]
System.out.println(LocalDate.of(2026, 9, 6).atStartOfDay(ZoneId.of("America/Santiago")));
// 2026-09-06T01:00-03:00[America/Santiago]

So get the start of a day in a zone with date.atStartOfDay(zone): it finds the first instant that actually exists. date.atTime(0, 0).atZone(zone) returns the same result here thanks to the gap shift, but any code that then assumes getHour() == 0 breaks in Havana and Santiago.

Two more quirks. Daylight saving isn't always exactly one hour: Australia/Lord_Howe moves its clocks by 30 minutes (getDaylightSavings() is PT30M in January 2026 and PT0S in July). And in the southern hemisphere summer falls in January: in Australia/Sydney the offset is +11:00 at 12:00 on 15 January 2026 and +10:00 on 15 July.

plusDays() or plusHours(24): arithmetic across a clock change

In ZonedDateTime, date-based units (days, weeks, months) preserve the wall-clock time, while time-based units (hours, minutes, Duration) preserve the physical interval. On ordinary days there is no difference, but on a clock-change day plusDays(1) and plusHours(24) differ by an hour, because that day is 23 or 25 hours long.

import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class DstArithmeticExample {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");

        ZonedDateTime before = ZonedDateTime.of(2026, 3, 28, 12, 0, 0, 0, berlin);
        System.out.println(before.plusDays(1));
        System.out.println(before.plusHours(24));
        System.out.println(Duration.between(before, before.plusDays(1)));
        System.out.println(ChronoUnit.HOURS.between(before, before.plusDays(1)));
        System.out.println(ChronoUnit.DAYS.between(before, before.plusDays(1)));

        ZonedDateTime autumn = ZonedDateTime.of(2026, 10, 24, 12, 0, 0, 0, berlin);
        System.out.println(Duration.between(autumn, autumn.plusDays(1)));
        System.out.println(autumn.plusHours(24));
    }
}
2026-03-29T12:00+02:00[Europe/Berlin]
2026-03-29T13:00+02:00[Europe/Berlin]
PT23H
23
1
PT25H
2026-10-25T11:00+01:00[Europe/Berlin]

The spring day lasts 23 hours, the autumn one 25. A “same time tomorrow” reminder needs plusDays(1); a “24 hours from now” timeout needs plusHours(24). The same choice between Period and Duration is covered in Duration vs Period: the difference. LocalDateTime doesn't see the clock change at all and counts 24 hours — see LocalDateTime vs Instant.

A daily event at 09:00 Berlin time “jumps” by an hour in UTC, and that is correct:

ZonedDateTime daily = ZonedDateTime.of(2026, 3, 28, 9, 0, 0, 0, ZoneId.of("Europe/Berlin"));
for (int i = 0; i < 3; i++) {
    ZonedDateTime d = daily.plusDays(i);
    System.out.println(d + " -> " + d.toInstant());
}
2026-03-28T09:00+01:00[Europe/Berlin] -> 2026-03-28T08:00:00Z
2026-03-29T09:00+02:00[Europe/Berlin] -> 2026-03-29T07:00:00Z
2026-03-30T09:00+02:00[Europe/Berlin] -> 2026-03-30T07:00:00Z

A scheduler that stores this as “every 24 hours from an instant in UTC” will start firing at 10:00 Berlin time after 29 March.

Comparing: equals(), isEqual() and compareTo()

To check whether two ZonedDateTime objects represent the same instant, use isEqual() or compare their toInstant() values. equals() also compares the local time and the zone, so 10:00 in New York and 16:00 in Berlin are different objects to it, even though they are the same moment.

ZonedDateTime ny = ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, ZoneId.of("America/New_York"));
ZonedDateTime be = ny.withZoneSameInstant(ZoneId.of("Europe/Berlin"));

System.out.println(ny.equals(be));                          // false
System.out.println(ny.isEqual(be));                         // true
System.out.println(ny.compareTo(be));                       // -1
System.out.println(ny.toInstant().equals(be.toInstant()));  // true

compareTo() didn't return 0: it compares the instant first, then the local time, then the zone ID. That's why identical instants in different zones are not treated as equal when sorting.

It gets subtler when even the offset matches but the zone is expressed differently:

ZonedDateTime x = ZonedDateTime.of(2026, 7, 15, 10, 0, 0, 0, ZoneId.of("Europe/Berlin"));
ZonedDateTime y = x.withZoneSameInstant(ZoneOffset.ofHours(2));

System.out.println(y);                                                    // 2026-07-15T10:00+02:00
System.out.println(x.equals(y));                                          // false
System.out.println(x.isEqual(y));                                         // true
System.out.println(new HashSet<>(List.of(x, y)).size());                 // 2
System.out.println(Comparator.comparing(ZonedDateTime::toInstant).compare(x, y)); // 0
System.out.println(x.toOffsetDateTime().equals(y.toOffsetDateTime()));    // true

Put such objects in a HashSet or use them as HashMap keys, and the “duplicates” won't collapse. For collections and sorting by instant, use Instant or the comparator Comparator.comparing(ZonedDateTime::toInstant).

ZoneRules: what a zone knows about transitions

ZoneRules (zone.getRules()) holds a zone's rules: which offset applies at any instant, whether it is standard or daylight time, and when the previous and next transitions are. With it you can check whether daylight saving time is in effect without creating a ZonedDateTime at all.

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneRules;

public class ZoneRulesExample {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");
        ZoneRules r = berlin.getRules();

        Instant summer = ZonedDateTime.of(2026, 7, 1, 12, 0, 0, 0, berlin).toInstant();
        Instant winter = ZonedDateTime.of(2026, 12, 2, 12, 0, 0, 0, berlin).toInstant();

        System.out.println(r.isDaylightSavings(summer) + " " + r.getOffset(summer)); // true +02:00
        System.out.println(r.getStandardOffset(summer));                             // +01:00
        System.out.println(r.getDaylightSavings(summer));                            // PT1H
        System.out.println(r.isDaylightSavings(winter) + " " + r.getOffset(winter)); // false +01:00

        ZoneOffsetTransition next = r.nextTransition(winter);
        System.out.println(next);                      // Transition[Gap at 2027-03-28T02:00+01:00 to +02:00]
        System.out.println(next.getDateTimeBefore());  // 2027-03-28T02:00
        System.out.println(next.getDateTimeAfter());   // 2027-03-28T03:00
        System.out.println(next.isGap());              // true
        System.out.println(next.getDuration());        // PT1H
        System.out.println(next.getInstant());         // 2027-03-28T01:00:00Z
        System.out.println(r.previousTransition(winter));
        // Transition[Overlap at 2026-10-25T03:00+02:00 to +01:00]

        ZoneRules moscow = ZoneId.of("Europe/Moscow").getRules();
        System.out.println(moscow.nextTransition(winter));      // null
        System.out.println(moscow.previousTransition(winter));
        // Transition[Overlap at 2014-10-26T02:00+04:00 to +03:00]
        System.out.println(moscow.isFixedOffset());                          // false
        System.out.println(ZoneOffset.ofHours(3).getRules().isFixedOffset()); // true
    }
}

Berlin's future transitions are computed from getTransitionRules(): in spring “SUNDAY on or after MARCH 25 at 01:00 UTC”, in autumn “SUNDAY on or after OCTOBER 25 at 01:00 UTC”. In plain words, the last Sunday of March and of October at 01:00 UTC, at the same moment across the whole EU.

Moscow has no next transition: Russia abolished seasonal clock changes in 2011 and has stayed on +03:00 permanently since 26 October 2014. Yet the zone is not “fixed” — it has a history, and Java uses it for past dates:

ZoneId moscow = ZoneId.of("Europe/Moscow");
System.out.println(ZonedDateTime.of(2012, 7, 1, 12, 0, 0, 0, moscow).getOffset()); // +04:00
System.out.println(ZonedDateTime.of(2016, 7, 1, 12, 0, 0, 0, moscow).getOffset()); // +03:00

Europe/Moscow ≠ +03:00

Today both give the same wall-clock time, so they look interchangeable. For archived data from before October 2014, though, ZoneId.of("Europe/Moscow") and ZoneOffset.ofHours(3) produce different instants: in summer 2012 Moscow was on +04:00. When you recompute historical dates, use the region, not the offset.

tzdata updates and future events

Time zone rules are set by governments, and they change: Russia dropped clock changes in 2011 and changed its offset in 2014, and the EU has debated abolishing seasonal time changes. Java takes its rules from the IANA tz database bundled inside the JDK (the tzdb.dat file), so your results depend on the version of that database.

To find out which version you have:

System.out.println(ZoneRulesProvider.getVersions("Europe/Berlin").lastKey());
// 2026a on JDK 25.0.3; 2023c on an older JDK 21 build

The database is updated by updating the JDK (patch releases ship with new tzdata) or, if upgrading the JDK isn't an option, with Oracle's Timezone Updater Tool (tzupdater).

This leads to a practical storage rule. For past events, store an Instant (or OffsetDateTime): the moment has already happened, and future rule changes can't touch it. For future events scheduled in local time (a meeting on 15 May 2027 at 10:00 in Berlin), store LocalDateTime + ZoneId and compute the instant when you need it. If the rules change, a precomputed Instant drifts away from 10:00, while the “local time + zone” pair yields the right instant after the JDK update.

ZonedDateTime vs OffsetDateTime: what to store in a database and JSON

OffsetDateTime stores a date, a time and a fixed offset (+01:00) with no clock-change rules. ZonedDateTime stores a region and knows its rules. For a single instant the two are equivalent, but the arithmetic differs: when you add days to an OffsetDateTime, it keeps its offset even if the region changed its clocks in between.

ZoneId berlin = ZoneId.of("Europe/Berlin");
ZonedDateTime z = ZonedDateTime.of(2026, 3, 28, 9, 0, 0, 0, berlin);

System.out.println(z.plusDays(1));
// 2026-03-29T09:00+02:00[Europe/Berlin]

OffsetDateTime o = z.toOffsetDateTime().plusDays(1);
System.out.println(o);
// 2026-03-29T09:00+01:00
System.out.println(o.atZoneSameInstant(berlin));
// 2026-03-29T10:00+02:00[Europe/Berlin]  - Berlin clocks show 10:00, not 09:00

Converting between the classes: zdt.toOffsetDateTime(), odt.atZoneSameInstant(zone) and odt.toZonedDateTime() — with the last one, the zone is just the offset, so there are still no rules.

Where to store what. JDBC 4.2 supports OffsetDateTime as the standard mapping for TIMESTAMP WITH TIME ZONE (rs.getObject(col, OffsetDateTime.class)), while support for ZonedDateTime is not required by the JDBC spec. In JSON and REST APIs, send an ISO string with an offset or an Instant; if you need the region (to compute “same time next day” later), send it as a separate field.

What to store What it holds DST rules Where to use it
Instant An instant on the UTC timeline Not needed Past events, logs, audit trails
OffsetDateTime Instant + offset at that moment No TIMESTAMP WITH TIME ZONE columns, JSON/APIs
ZonedDateTime Instant + region Yes In-memory calculations: zone conversion, calendar arithmetic
LocalDateTime + ZoneId (two fields) Local time + region Applied when computing Future events in local time: meetings, schedules

A comparison of all java.time classes, zones aside, is in the table in java.time classes: which one to pick.

Legacy API: TimeZone and GregorianCalendar

In legacy code a time zone is a java.util.TimeZone, and a date with a zone is a GregorianCalendar. The bridges to java.time are TimeZone.getTimeZone(zoneId) and timeZone.toZoneId(), GregorianCalendar.from(zdt) and calendar.toZonedDateTime(), and for Date, Date.from(zdt.toInstant()).

ZonedDateTime z = ZonedDateTime.of(2026, 3, 28, 9, 0, 0, 0, ZoneId.of("Europe/Berlin"));

GregorianCalendar cal = GregorianCalendar.from(z);
System.out.println(cal.toZonedDateTime());       // 2026-03-28T09:00+01:00[Europe/Berlin]
Date date = Date.from(z.toInstant());
TimeZone tz = TimeZone.getTimeZone(ZoneId.of("Europe/Berlin"));
System.out.println(tz.getID());                  // Europe/Berlin

TimeZone typo = TimeZone.getTimeZone("Europe/Moskow");   // typo
System.out.println(typo.getID());                // GMT
System.out.println(typo.getRawOffset());         // 0

ZoneId.of("Europe/Moskow");
// ZoneRulesException: Unknown time-zone ID: Europe/Moskow

A typo in the old API raises no error: TimeZone.getTimeZone() silently returns GMT, and the program runs with offset 0 instead of +3. ZoneId.of() fails right away, on the line with the mistake. That alone is a good reason to move to java.time. How Date and Calendar compare to the new classes and how to convert between them is covered in Date vs LocalDate.

ZonedDateTime and ZoneId method cheat sheet

ZonedDateTime mirrors the LocalDateTime methods (getters, with*, plus*, minus*) and adds methods for zones and transitions. The table lists the zone-specific ones and how they behave in edge cases.

Method What it does Edge case / error
ZoneId.of(id), ZoneId.of(id, SHORT_IDS) Zone from an ID or a short name Typo, "MSK", wrong case — ZoneRulesException; "EST" → America/Panama
ZoneId.getAvailableZoneIds() All region IDs Count depends on the tzdata version; the set is unsorted
ZoneOffset.ofHours(h), ofHoursMinutes(h, m) Fixed offset Outside minus 18…plus 18 hours — DateTimeException
of(...), ldt.atZone(zone) ZonedDateTime from a local time Gap — shifted forward; overlap — earlier offset
ofStrict(ldt, offset, zone) Creation with strict validation Time in a gap or a wrong offset — DateTimeException
ofLocal(ldt, zone, preferredOffset) Creation with a preferred offset An invalid offset is silently ignored
ofInstant(instant, zone) ZonedDateTime from an instant No ambiguity, even in an overlap
parse(text) Parses an ISO string No offset — DateTimeParseException; offset contradicts zone — the offset wins
withZoneSameInstant(zone) Same instant in another zone Half-hour offsets (Asia/Kolkata) give 19:30 and the like
withZoneSameLocal(zone) Same wall-clock time in another zone This is a different instant
withEarlierOffsetAtOverlap(), withLaterOffsetAtOverlap() Choose the offset in an overlap Outside an overlap they return the same object
plusDays() vs plusHours() Calendar vs physical shift On a clock-change day the results differ by an hour
isEqual(), equals(), compareTo() Comparison Same instant in different zones: isEqual true, equals false, compareTo ≠ 0
getRules(): getValidOffsets(), getTransition(), nextTransition() Zone rules and transitions For a zone with no future transitions, nextTransition() is null
toInstant(), toOffsetDateTime(), toLocalDateTime() Convert to other classes toLocalDateTime() drops the zone and offset

Where developers get time zones wrong

Nearly every time zone bug comes from replacing a zone with a number or picking the wrong method. Such code passes tests for most of the year and breaks in the days and weeks around a clock change, exactly when nobody is looking.

Mistake What happens Do this instead
A hard-coded “plus 3 hours” or a ZoneOffset instead of a region Off by an hour around clock changes and for historical dates ZoneId.of("Europe/Berlin") and withZoneSameInstant()
ZoneId.of("MSK"), ZoneId.of("PST") ZoneRulesException: Unknown time-zone ID Full ID: Europe/Moscow, America/Los_Angeles
withZoneSameLocal() to convert a time You get a different instant with the same 10:00 on the clock withZoneSameInstant()
plusHours(24) for “same time tomorrow” An hour early or late on a clock-change day plusDays(1); for a timeout, the other way round — plusHours(24)
equals() to check “same instant” false for the same instant in different zones; duplicates in a HashSet isEqual() or compare toInstant()
A future meeting stored as an Instant After a zone rule change the meeting drifts away from 10:00 LocalDateTime + ZoneId, compute the instant when needed
ZoneId.systemDefault() on a server The result depends on the machine's settings The user's zone from their profile, or an explicit constant
date.atTime(0, 0).atZone(zone) plus an assumption that getHour() == 0 In Havana and Santiago the day starts at 01:00 date.atStartOfDay(zone)
ofStrict() on user input without a try An unhandled DateTimeException once a year Catch the exception or check getValidOffsets() first

Frequently Asked Questions

How do I list all Java time zones with their current offset?

ZoneId.getAvailableZoneIds() returns an unsorted Set<String>. Sort it and, for each ID, take the offset at one and the same instant: Instant now = Instant.now(); ZoneId.getAvailableZoneIds().stream().sorted().forEach(id -> System.out.println(id + " " + ZoneId.of(id).getRules().getOffset(now)));. The offset has to be taken at a specific instant: Berlin is +02:00 in summer and +01:00 in winter. For a drop-down in a UI, people usually keep IDs of the form Continent/City and drop the legacy aliases.

How can I tell whether daylight saving time is in effect right now?

Call zone.getRules().isDaylightSavings(Instant.now()). The size of the current shift comes from getDaylightSavings(Instant.now()): usually PT1H, but PT30M for Australia/Lord_Howe. For Europe/Moscow the answer is always false because daylight saving time was abolished there. The date of the next clock change comes from nextTransition() — see ZoneRules.

How do I print a ZonedDateTime without [Europe/Berlin] at the end?

toString() prints both the offset and the region in square brackets — that's the ISO_ZONED_DATE_TIME format, a Java extension of ISO-8601. For a standard string with an offset, use z.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME): for 28 March 2026, 09:00 in Berlin that's 2026-03-28T09:00:00+01:00. z.toOffsetDateTime().toString() gives a similar result without zero seconds: 2026-03-28T09:00+01:00. Any ISO-8601 parser understands this string, unlike the version with [Europe/Berlin].

What is the difference between ZoneId.of("UTC") and ZoneOffset.UTC?

ZoneId.of("UTC") is a region (ZoneRegion) with the ID UTC, while ZoneOffset.UTC is the offset Z. They give the same time but are objects of different classes: ZoneId.of("UTC").equals(ZoneOffset.UTC) returns false, and ZonedDateTime objects created with them are not equal by equals() either (though isEqual() returns true). To turn the region into an offset, call normalized(): ZoneId.of("UTC").normalized() returns Z. Why equals() looks at the zone is explained in Comparing.

Practice

Reinforce this lesson with hands-on tasks, each with a level and a time estimate.

All module tasks →

Comments

Please log in or register to have a possibility to add comment.