ZonedDateTime
A date and time in a specific time zone — with daylight saving time taken into account.
Available since: Java 8
Syntax
public final class ZonedDateTime implements Temporal, ChronoZonedDateTime<LocalDate>Examples
One meeting in different cities:
void main() {
ZonedDateTime berlin = ZonedDateTime.of(2025, 3, 14, 15, 0, 0, 0, ZoneId.of("Europe/Berlin"));
ZonedDateTime tokyo = berlin.withZoneSameInstant(ZoneId.of("Asia/Tokyo"));
ZonedDateTime newYork = berlin.withZoneSameInstant(ZoneId.of("America/New_York"));
IO.println(berlin);
IO.println(tokyo.toLocalTime());
IO.println(newYork.toLocalTime());
}Output:
2025-03-14T15:00+01:00[Europe/Berlin]
23:00
10:00A daylight saving change: a day 23 hours long:
void main() {
ZoneId zone = ZoneId.of("Europe/Berlin");
ZonedDateTime before = ZonedDateTime.of(2025, 3, 29, 12, 0, 0, 0, zone);
ZonedDateTime after = before.plusDays(1);
IO.println(Duration.between(before, after).toHours());
IO.println(after.getOffset());
}Output:
23
+02:00Notes
Specify a zone by its IANA name (Europe/Berlin, America/New_York), not by an offset like +01:00: only the name knows the daylight saving rules. The current time in a zone is ZonedDateTime.now(zone), the computer's zone is ZoneId.systemDefault().
See also
- Instant — An exact moment on the UTC timeline — for logs, timestamps and measurements.
- LocalDateTime — A date and time without a time zone — for example, a meeting in a calendar.
- DateTimeFormatter.ofPattern() — Creates a formatter for printing and parsing dates with a pattern such as dd.MM.yyyy.
Related recipes
In the tutorial
- Dates and times — The java.time package — LocalDate, LocalTime, LocalDateTime, date arithmetic, Period, Duration, ChronoUnit, time zones and Instant.