Skip to content
Tutorials Center
My learning

Topics

Java Reference ยท Date and Time

The ZonedDateTime class

Reference for java.time.ZonedDateTime: date-time with a time zone, converting between zones, daylight saving gaps and overlaps, and elapsed vs calendar arithmetic.

java.time.ZonedDateTime is a date, a time, a UTC offset and a time-zone region together, for example 2025-07-14T09:30+02:00[Europe/Paris]. The region (a ZoneId) carries the rules that tell Java which offset applies at each moment, including daylight saving changes. This makes ZonedDateTime the class for human-facing schedules: meetings, flights, appointments.

It identifies exactly one moment on the timeline, so it converts to and from Instant without ambiguity. Its arithmetic is zone-aware: adding a day keeps the local time, while adding 24 hours moves by exactly that much elapsed time, which can differ by an hour on a daylight-saving day.

Java
ZonedDateTime paris = ZonedDateTime.of(2025, 7, 14, 9, 30, 0, 0, ZoneId.of("Europe/Paris"));
ZonedDateTime tokyo = paris.withZoneSameInstant(ZoneId.of("Asia/Tokyo"));

Try it

Java Converting between zones

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Java Daylight saving gaps, overlaps and arithmetic

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Syntax

Java
public final class ZonedDateTime implements Temporal, ChronoZonedDateTime<LocalDate>, Serializable
Member Description
now(), now(ZoneId), now(Clock) Current date-time in the default zone, a zone or a clock.
of(y, m, d, h, min, s, nano, ZoneId) From fields.
of(LocalDateTime, ZoneId) From a local date-time and zone; resolves gaps and overlaps.
ofInstant(Instant, ZoneId) Exact conversion from an instant.
ofStrict(LocalDateTime, ZoneOffset, ZoneId) Fails if the offset is not valid for the zone.
parse(CharSequence) Text such as 2025-07-14T09:30+02:00[Europe/Paris].
withZoneSameInstant(ZoneId) / withZoneSameLocal(ZoneId) Change the zone keeping the moment or the wall clock.
withEarlierOffsetAtOverlap() / withLaterOffsetAtOverlap() Choose in an overlap.
getOffset(), getZone() Offset and region.
toInstant(), toLocalDate(), toLocalTime(), toLocalDateTime(), toOffsetDateTime() Conversions.
plusDays/Weeks/Months/Years Calendar arithmetic on local time.
plusHours/Minutes/Seconds/Nanos Elapsed-time arithmetic on the timeline.
isBefore, isAfter, isEqual, equals, format(...) Comparison and text.

Throws: DateTimeException for invalid values or a strict mismatch, DateTimeParseException for bad text.

Usage notes

  • Gaps move forward, overlaps pick the earlier offset. ZonedDateTime.of never fails for a nonexistent local time: it shifts the time forward by the length of the gap.
  • Date units vs time units. plusDays operates on the local date and keeps the clock time where possible; plusHours operates on the instant. The two differ by an hour on a daylight-saving boundary.
  • equals includes the zone, so the same instant in two zones is not equal; isEqual and toInstant().equals(...) compare the moment. Do not use a ZonedDateTime as a map key unless you want the zone to matter.
  • Zone rules change. Governments change daylight-saving rules; a stored future ZonedDateTime may shift when the JDK's time-zone data updates. Store the local date-time and the zone ID for future appointments, not only the instant.
  • Prefer region IDs (Europe/Paris) over fixed offsets (+02:00) for anything that spans a year; fixed offsets do not know about daylight saving.
  • For databases and APIs, convert to Instant or OffsetDateTime; zone IDs do not travel well.
  • The default zone (ZoneId.systemDefault()) is the JVM's setting and varies by server; pass a zone explicitly.