Scrivio Interview library
CodingFoundations6 min read · updated 12 November 2026

What does this print, assuming America/New_York and the US DST change on 2025-03-09 at 02:00?

Java
ZonedDateTime z = ZonedDateTime.of(2025, 3, 9, 2, 30, 0, 0, ZoneId.of("America/New_York"));
System.out.println(z);

It prints 2025-03-09T03:30-04:00[America/New_York]. On that date New York clocks jump from 02:00 straight to 03:00, so 02:30 does not exist; ZonedDateTime.of does not throw, it moves a time in the gap forward by the length of the gap, one hour, and uses the new summer offset. ZonedDateTime.ofStrict would throw instead, and in the autumn overlap the earlier offset is chosen unless we ask for withLaterOffsetAtOverlap().

Why this question is asked

Most of the year, turning a local date and time into a ZonedDateTime is boring: there is exactly one offset and one moment. Twice a year it is not, and that is when scheduling and billing code breaks. Interviewers ask this snippet to see whether we know that some local times do not exist and others happen twice, and what Java does about each. In this answer, we will recap DST gaps and overlaps, run the snippet and explain the result, compare it with ofStrict, look at the autumn overlap, and finally see how to detect a gap in our own code.

1A Quick Recap of Gaps and Overlaps

A time zone such as America/New_York is a set of rules mapping local times to offsets from UTC. In winter New York is at -05:00 and in summer at -04:00. The switches create two awkward situations.

In spring, at 02:00 local time, clocks jump to 03:00. Every local time from 02:00 to 02:59 is skipped; it never appears on a New York clock that night. That stretch is called a gap. In autumn, at 02:00 local time, clocks go back to 01:00, so every time from 01:00 to 01:59 happens twice, first at -04:00 and then at -05:00. That stretch is called an overlap. A local date-time in a gap has zero valid offsets, and one in an overlap has two.

Java
ZoneRules rules = ZoneId.of("America/New_York").getRules();
System.out.println(rules.getValidOffsets(LocalDateTime.of(2025, 3, 9, 2, 30))); // []
System.out.println(rules.getValidOffsets(LocalDateTime.of(2025, 3, 9, 4, 30))); // [-04:00]
System.out.println(rules.getValidOffsets(LocalDateTime.of(2025, 11, 2, 1, 30))); // [-04:00, -05:00]
Local times around the 2025 New York changes
Local timeValid offsetsSituation
2025-03-09 01:30-05:00normal, winter time
2025-03-09 02:30nonegap: clocks jump 02:00 -> 03:00
2025-03-09 03:30-04:00normal, summer time
2025-11-02 01:30-04:00 and -05:00overlap: this hour happens twice

2Running the Snippet

Now the code from the question. We ask for 02:30 on the gap night.

Java
ZonedDateTime z = ZonedDateTime.of(2025, 3, 9, 2, 30, 0, 0, ZoneId.of("America/New_York"));
System.out.println(z); // 2025-03-09T03:30-04:00[America/New_York]
System.out.println(z.toInstant()); // 2025-03-09T07:30:00Z

Notice three things. No exception was thrown. The hour changed from 2 to 3, so the object does not hold the local time we asked for. And the offset is -04:00, the summer offset that applies after the jump.

3Why Java Moves the Time Forward

ZonedDateTime.of first builds a LocalDateTime and then asks the zone rules for its offset. When the rules say there is no valid offset, Java has to choose between failing and adjusting. The documented choice for of() is to adjust: the local date-time is moved later by the length of the gap, which is one hour here, and the offset after the transition is used. So 02:30 becomes 03:30-04:00.

The reason for this choice is practical. Most code that builds a time from user input or from a schedule would rather get a sensible nearby time than crash once a year. One way to think about it is that 02:30 in the old offset, -05:00, is the same moment as 03:30 in the new one, -04:00: 07:30 UTC in both cases. So Java keeps the moment that 02:30 would have meant if the clocks had not changed yet. But there is a catch: our code silently got a different local time than it asked for, and if it later formats only the time, the user sees 03:30.

Step throughHow ZonedDateTime.of resolves a local time
  1. Build LocalDateTime 2025-03-09T02:30
  2. Ask zone rules for valid offsetsAmerica/New_York returns none
  3. How many valid offsets?0 means gap, 2 means overlap
  4. Gap?
    YesShift later by gap length, use offset after: 03:30-04:00NoOverlap: use earlier offset, or the normal single one

4 steps in order. Play them, or step through them one at a time.

4When We Want an Error Instead: ofStrict

Sometimes silently moving the time is wrong, for example when validating a time a user typed for a flight. ZonedDateTime.ofStrict checks that the combination of local date-time, offset and zone is valid, and throws if it is not.

Java
ZonedDateTime.ofStrict(LocalDateTime.of(2025, 3, 9, 2, 30),
ZoneOffset.ofHours(-5), ZoneId.of("America/New_York"));
// java.time.DateTimeException: LocalDateTime '2025-03-09T02:30' does not exist
// in zone 'America/New_York' due to a gap in the local time-line, typically caused by daylight savings

Notice that ofStrict needs the offset as well as the zone, because its job is to check that all three agree. It fails for a gap and also for an offset that does not match, such as -04:00 in January.

5The Autumn Overlap: Earlier by Default

In the overlap there are two valid moments for 01:30 on 2 November 2025. ZonedDateTime.of picks the earlier offset, -04:00, which is the first time the clock shows 01:30. If we mean the second time, we ask for it explicitly.

Java
ZonedDateTime first = ZonedDateTime.of(2025, 11, 2, 1, 30, 0, 0, ZoneId.of("America/New_York"));
System.out.println(first); // 2025-11-02T01:30-04:00[America/New_York]
System.out.println(first.withLaterOffsetAtOverlap()); // 2025-11-02T01:30-05:00[America/New_York]
System.out.println(first.withLaterOffsetAtOverlap().toInstant()); // 2025-11-02T06:30:00Z, one hour later

The two results show the same local time but are one hour apart on the timeline. withEarlierOffsetAtOverlap() switches back. Outside an overlap, both methods return the object unchanged, so they are safe to call.

6Follow-up questions

How would you detect that a requested local time fell into a gap?

Ask the zone rules before building the ZonedDateTime: if zone.getRules().getValidOffsets(localDateTime) is empty, the time is in a gap, and if it has two entries, it is in an overlap. getTransition(localDateTime) also returns the ZoneOffsetTransition, and its isGap() method confirms the case and tells us when the jump happens. A simpler check after the fact is to compare zdt.toLocalDateTime() with the local date-time we asked for; if they differ, Java adjusted it.

What should a scheduler do with a job set for 02:30 on the gap night?

It depends on the business rule, and the rule should be written down. A daily report probably should run at 03:30 rather than be skipped, which is what ZonedDateTime.of gives us. An alarm might be skipped instead. Some scheduling libraries skip times in the gap and others shift them, so check yours and test it.

Does the same snippet behave the same in every Java version?

The resolution rules for of(), ofStrict() and the overlap methods have been stable since Java 8. What can change is the time zone data itself, which comes with JDK updates, so the dates of the gap depend on the tzdata version the JDK carries.

7Conclusion

In this answer, we saw that on 9 March 2025 New York skips the hour from 02:00 to 03:00, so 02:30 has no valid offset. ZonedDateTime.of does not throw; it shifts the time forward by the length of the gap and prints 2025-03-09T03:30-04:00[America/New_York]. ZonedDateTime.ofStrict throws a DateTimeException instead. In the autumn overlap, of() chooses the earlier offset, and withLaterOffsetAtOverlap() selects the later one. To detect a gap, we check the zone rules' valid offsets or compare the resulting local time with the one we asked for.

What to say in the interviewAbout 70 seconds aloud

Open with

It prints 2025-03-09T03:30 minus 04:00 in America/New_York. The reason is that at 2 a.m. on that date New York clocks jump straight to 3 a.m., so 02:30 never happens; it is in a DST gap and has no valid offset.

Then, if they want more

ZonedDateTime.of does not throw in that case. Its documented behaviour is to move the local time later by the length of the gap, one hour, and use the offset after the transition, so we get 03:30 at minus four, which is the same instant as 02:30 at the old winter offset would have been, 07:30 UTC.

If I want an exception instead, I would use ZonedDateTime.ofStrict with the offset and zone, which throws a DateTimeException saying the local time does not exist due to a gap. The opposite case is the autumn overlap, where 01:30 happens twice. There, of picks the earlier offset by default, minus four, and withLaterOffsetAtOverlap gives the second one at minus five.

To detect a gap in my own code, I would check getValidOffsets on the zone rules for an empty list, or compare the resulting local time with the one I requested.

About this answer

Last updated
12 November 2026
Versions it names
Java 8
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does this print, assuming America/New_York and the US DST change on 2025-03-09 at...": https://scrivio-interview-library.netlify.app/java/date-and-time/8a8205b473/