Quick revision
The short answer
A Duration is an exact amount of time measured in seconds and nanoseconds, while a Period is an amount of calendar time in years, months and days. On a DST change day, Duration.ofDays(1) adds exactly 24 hours, so the local time shifts by an hour, while Period.ofDays(1) adds one calendar day and keeps the local time when it exists. Duration suits timeouts and elapsed time, Period suits calendar logic such as subscriptions, and only Period can be added to a LocalDate.
What to remember
In this answer, we saw that a Duration stores exact seconds and nanoseconds and works on the instant timeline, while a Period stores years, months and days and works on the local calendar. On a DST change day in New York, Duration.ofDays(1) moved 09:00 to 10:00 because it adds exactly 24 hours, and Period.ofDays(1) kept 09:00. A Duration cannot be added to a LocalDate, and a Period of months cannot be added to an Instant. Durations suit timeouts and elapsed time, and Periods suit calendar logic like subscriptions.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A Duration is an exact amount of time measured in seconds and nanoseconds, while a Period is an amount of calendar time in years, months and days. On a DST change day, Duration.ofDays(1) adds exactly 24 hours, so the local time shifts by an hour, while Period.ofDays(1) adds one calendar day and keeps the local time when it exists. Duration suits timeouts and elapsed time, Period suits calendar logic such as subscriptions, and only Period can be added to a LocalDate.
Why this question is asked
Durations and periods look interchangeable in simple tests, because on most days a day is 24 hours. The difference shows up twice a year and at every month end, which is exactly when billing, scheduling and expiry logic is tested hardest by reality. Interviewers ask this to see whether we know the two different meanings of 'one day' and can pick the right one. In this answer, we will look at what each class stores, add both to a ZonedDateTime on a DST change day, see why the results differ, look at which types each can be added to, and finish with a rule for choosing.
1What Each Class Stores
A Duration is machine time. Internally it is a number of seconds plus a number of nanoseconds. When we write Duration.ofDays(1), Java immediately converts it to 86,400 seconds; it does not remember the word 'day'. A Period is human calendar time. It stores three separate numbers, years, months and days, and does not convert between them, because a month has no fixed length in days and, in a zone with DST, a day has no fixed length in hours.
Notice how each prints in ISO-8601 duration format: PT24H means a time-based amount of 24 hours, and P1M1D means one month and one day. The T separates the date part from the time part, which reflects exactly the split between the two classes.
2Adding Both on a DST Change Day
In America/New_York, clocks jumped from 02:00 to 03:00 on 9 March 2025, so that calendar day had only 23 hours. Let us add 'one day' to 09:00 on 8 March in both ways.
| Added amount | Works on | Result | Elapsed |
|---|---|---|---|
Duration.ofDays(1) | instant timeline | 2025-03-09 10:00 -04:00 | 24 h |
Period.ofDays(1) | local calendar | 2025-03-09 09:00 -04:00 | 23 h |
The Duration landed at 10:00 local time and the Period at 09:00. Both are correct answers to different questions. The Duration answers 'what time is it 24 hours from now?', and because the night was an hour short, 24 hours later the wall clock reads 10:00. The Period answers 'what is the same time tomorrow?', which is 09:00, only 23 hours later. On the autumn change, the effect reverses: the Duration lands at 08:00 and the Period still at 09:00.
3Why the Results Differ
When we add a Duration to a ZonedDateTime, Java works on the instant timeline: it takes the moment, adds the seconds, and converts the result back to local time using the zone's rules. When we add a Period, Java works on the local timeline: it adds days to the date, keeps the local time 09:00, and only then resolves that local date-time in the zone, picking up the new summer offset.
There is a small catch with Period. If the target local time does not exist, because it falls into the DST gap, Java shifts it forward by the length of the gap. So 02:30 plus Period.ofDays(1) onto the spring change night gives 03:30. That is why we say Period keeps the local time 'when it exists'.
- Amount is a Duration?YesConvert to instant, add seconds, back to localNoIt is a Period: add years, months, days to the date
- Keep the same local time
- Resolve local date-time in the zonegap: shift forward; overlap: keep offset if valid
3 steps in order. Play them, or step through them one at a time.
4Which Types Each Can Be Added To
A Duration needs a time-based type, one with hours and seconds. A Period needs a date-based type, one with days and months. So a Duration cannot be added to a LocalDate, which has no time of day, and Java tells us so at runtime.
Instant is the mirror case. It works with Durations and with whole days as 24-hour units, but adding Period.ofMonths(1) to an Instant throws, because an instant has no calendar and so no idea how long 'a month' is.
5Choosing Between Them
The rule is to ask what the business means. Timeouts, retry delays, session lifetimes, rate-limit windows and measured elapsed time are about physical time passing, so they are Durations, usually applied to an Instant. Subscriptions, trial periods, 'due in 30 days', anniversaries and daily reminders at a fixed wall-clock time are about the calendar, so they are Periods, applied to a LocalDate or a ZonedDateTime. When a requirement says 'one day', it is worth asking which one is meant, because the two answers differ on exactly the days customers notice.
6Follow-up questions
What do Duration.between and Period.between return?
Duration.between takes two time-based values, such as two Instants, and returns the exact seconds and nanoseconds between them. Period.between takes two LocalDates and returns years, months and days, for example 2025-01-15 to 2025-03-20 is P2M5D. For a count in a single unit, ChronoUnit.DAYS.between(a, b) is often clearer.
Why does Duration.ofDays exist if days are calendar units?
For convenience when we really mean 24-hour blocks, such as a cache that expires in 'one day' of elapsed time. It is defined as exactly 24 hours; it never looks at a calendar.
How should a 30-day trial be computed?
As a Period on a LocalDate in the customer's zone, startDate.plusDays(30), or plus(Period.ofDays(30)), and then the end moment is the start of that day in the customer's zone. Using a Duration of 30 times 24 hours from an Instant would be an hour off if a DST change falls inside the trial.
7Conclusion
In this answer, we saw that a Duration stores exact seconds and nanoseconds and works on the instant timeline, while a Period stores years, months and days and works on the local calendar. On a DST change day in New York, Duration.ofDays(1) moved 09:00 to 10:00 because it adds exactly 24 hours, and Period.ofDays(1) kept 09:00. A Duration cannot be added to a LocalDate, and a Period of months cannot be added to an Instant. Durations suit timeouts and elapsed time, and Periods suit calendar logic like subscriptions.
Open with
A Duration is a time-based amount: seconds and nanoseconds. Duration.ofDays(1) is converted straight to 86,400 seconds. A Period is a date-based amount in years, months and days, kept separately, because months and, with DST, days have no fixed length.
Then, if they want more
When I add them to a ZonedDateTime, Duration works on the instant timeline: it adds exactly 24 hours and converts back, so on a DST change day the local time shifts. For example, from 09:00 on the day before the spring change in New York, I get 10:00 the next day.
Period works on the local calendar: it adds one day to the date, keeps 09:00, and then resolves it with the new offset. If the target time falls in a DST gap, it is moved forward.
That also explains which types they work with: a Duration can't be added to a LocalDate, it throws an unsupported unit exception for seconds, while a Period can, and you can't add a Period of months to an Instant.
So I use Duration for timeouts, retries and measured elapsed time, usually on Instants, and Period for calendar logic like subscriptions, trials and reminders at the same local time.
About this answer
- Last updated
- 12 November 2026
- 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.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 is the difference between Duration and Period? What do Duration.ofDays(1) and...": https://scrivio-interview-library.netlify.app/java/date-and-time/ad4e5ee946/