Java LocalDateTime atZone() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

Definition

In Java, dt.atZone(zone) combines a LocalDateTime with a ZoneId such as Asia/Kolkata. The result is a ZonedDateTime, which is a real moment on the timeline and knows its own offset.

In most cases the local date and time stay the same. The exception is a daylight saving gap, where the time does not exist, and Java moves it forward.

An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.

Syntax

Pass a ZoneId. Create one with ZoneId.of("Region/City").

Java
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);

ZonedDateTime india = dt.atZone(ZoneId.of("Asia/Kolkata"));   // 2026-03-15T10:30+05:30[Asia/Kolkata]
CallWhat it does
dt.atZone(zone)The date-time with a zone.
zdt.withZoneSameInstant(zone)The same moment as seen in another zone.
zdt.toInstant()The exact moment, as an Instant.
zdt.toLocalDateTime()Drops the zone, and gives back a LocalDateTime.

Use ZoneId.of("Asia/Kolkata") and not short names such as IST, which are unclear.

Library declarations
Java
// java.time.LocalDateTime
public ZonedDateTime atZone(ZoneId zone)

Parameters

ParameterDescription
zone (ZoneId)The time zone to use. It must not be null.

Return Value

Return ValueDescription
ZonedDateTimeThe date-time combined with the zone, with the correct offset worked out.

Compare with Similar Methods

Ways to give a date-time a zone or offset:

MethodHow it differs
atOffset(offset)Uses a fixed offset, with no daylight saving rules.
LocalDateTime.ofInstant(instant, zone)Goes the other way: from a moment to a local date-time.
LocalDateTime.now(zone)Gets the current local date-time in a given zone.

Java Examples

Example 1 — Attach a Time Zone to a Date-Time

Attach the India zone, and look at the offset and the real moment in UTC.

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

public class LdtAtZoneDemo {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);

        ZonedDateTime india = dt.atZone(ZoneId.of("Asia/Kolkata"));

        System.out.println("zoned:  " + india);
        System.out.println("offset: " + india.getOffset());
        System.out.println("moment: " + india.toInstant());
    }
}

How It Works

  1. A local date-time. 10:30 on 15 March 2026, with no zone.
  2. Add the zone. The result shows the local time, the offset +05:30, and the zone name in brackets.
  3. The offset. getOffset() gives the offset that applies on that date.
  4. The real moment. toInstant() shows the same moment in UTC: 5 hours 30 minutes earlier, at 05:00.

Example 2 — Convert a Time from One Zone to Another

It is 10:30 in Tokyo. Find out what time it is in New York at the same moment.

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

public class LdtAtZoneConvert {
    public static void main(String[] args) {
        LocalDateTime meeting = LocalDateTime.of(2026, 3, 15, 10, 30);

        ZonedDateTime tokyo = meeting.atZone(ZoneId.of("Asia/Tokyo"));
        ZonedDateTime newYork = tokyo.withZoneSameInstant(ZoneId.of("America/New_York"));

        System.out.println("Tokyo:    " + tokyo.toLocalDateTime());
        System.out.println("New York: " + newYork.toLocalDateTime());
        System.out.println("same moment: " + tokyo.toInstant().equals(newYork.toInstant()));
    }
}

How It Works

  1. Start in Tokyo. atZone() says that 10:30 is Tokyo time.
  2. Move to New York. withZoneSameInstant() keeps the moment and changes the clock reading.
  3. Thirteen hours back. On 15 March, New York is on daylight saving time, so it is 13 hours behind Tokyo. 10:30 becomes 21:30 on the previous day.
  4. Still one moment. The two Instant values are equal.

Example 3 — See How Daylight Saving Time Is Handled

In New York in 2026 the clocks went forward on 8 March and back on 1 November. Attach a zone to a time inside each change.

Java
import java.time.LocalDateTime;
import java.time.ZoneId;

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

        LocalDateTime gap = LocalDateTime.of(2026, 3, 8, 2, 30);
        LocalDateTime overlap = LocalDateTime.of(2026, 11, 1, 1, 30);

        System.out.println("gap:     " + gap.atZone(newYork));
        System.out.println("overlap: " + overlap.atZone(newYork));
        System.out.println("normal:  " + LocalDateTime.of(2026, 7, 4, 12, 0).atZone(newYork));
    }
}

How It Works

  1. A time that does not exist. At 02:00 on 8 March the clocks jump to 03:00, so 02:30 never happens.
  2. Gap: moved forward. Java moves the time ahead by the length of the gap, one hour, to 03:30. The offset is now -04:00.
  3. A time that happens twice. At 02:00 on 1 November the clocks go back to 01:00, so 01:30 appears twice.
  4. Overlap: the earlier one. Java picks the first 01:30, which is still on summer time, with the offset -04:00. The last line is an ordinary day in July, where nothing special happens.

Frequently Asked Questions

Use dt.atZone(ZoneId.of("Asia/Kolkata")), with the zone you need.
No. It says that the local time is in that zone. To convert to another zone, use withZoneSameInstant().
In a gap, the time is moved forward by the length of the gap, so 02:30 becomes 03:30.
The earlier offset, which is the first of the two times.
Use dt.atZone(fromZone).withZoneSameInstant(toZone).toLocalDateTime().

Next: compareTo()

Compare two date-times and get a negative, zero, or positive number.

compareTo() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful