Quick revision
The short answer
java.time gives a separate type for each kind of date and time value. A birthday is a LocalDate, a date with no time or zone; a store's daily opening time is a LocalTime; a log timestamp is an Instant, a point on the UTC timeline; a meeting in New York next month is a ZonedDateTime with ZoneId America/New_York so daylight saving rules apply; and an API field with an offset such as +02:00 is an OffsetDateTime. All java.time types are immutable and thread-safe.
What to remember
In this answer, we saw that java.time separates local values from points in time. A birthday is a LocalDate and a daily opening time is a LocalTime, because neither belongs to a zone. A log timestamp is an Instant, an exact moment comparable across servers. A future meeting in New York is a ZonedDateTime with America/New_York, so DST rules decide the offset for its date and keep it at the same local time. An API field carrying a fixed offset is an OffsetDateTime. All of these types are immutable and thread-safe.
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.
java.time gives a separate type for each kind of date and time value. A birthday is a LocalDate, a date with no time or zone; a store's daily opening time is a LocalTime; a log timestamp is an Instant, a point on the UTC timeline; a meeting in New York next month is a ZonedDateTime with ZoneId America/New_York so daylight saving rules apply; and an API field with an offset such as +02:00 is an OffsetDateTime. All java.time types are immutable and thread-safe.
Why this question is asked
Date and time bugs are some of the most common and most embarrassing in production: meetings that move by an hour after a clock change, logs that cannot be ordered across servers, birthdays that show a day early for users in another country. Almost all of them come from using the wrong type for the value. Interviewers ask this question because choosing the type is the real skill; the API calls are easy once the type is right. In this answer, we will recap the two families of java.time types, go through each of the five examples and why its type fits, compare them in one table, and look at the common wrong choices.
1A Quick Recap: Local Values and Points in Time
The java.time package, added in Java 8, splits values into two families. Local types describe what a calendar or a wall clock shows, with no time zone: LocalDate (2026-11-04), LocalTime (09:00) and LocalDateTime (2026-11-04T09:00). They do not identify a moment in time on their own, because 09:00 happens at a different moment in Tokyo than in New York.
The other family identifies an exact moment. Instant is a point on the UTC timeline, counted from 1970. OffsetDateTime is a local date and time plus a fixed offset from UTC, such as +02:00. ZonedDateTime is a local date and time plus a ZoneId, a region such as Europe/Paris whose rules, including daylight saving time (DST), decide the offset for each date. A zone is more than an offset: Paris is +01:00 in winter and +02:00 in summer.
Every java.time type is immutable and thread-safe. Methods such as plusDays return new objects, so values can be shared freely and stored in constants.
2A Birthday: LocalDate
A birthday is a calendar date. Someone born on 14 March celebrates on 14 March wherever they are, so it must not be tied to a zone or a time of day. If we stored it as a moment, say midnight UTC, a user in California would see it as 13 March in local time, the classic off-by-one-day bug.
MonthDay is handy for the recurring part, for example to check whether today is someone's birthday.
3A Store's Opening Time: LocalTime
"We open at 09:00" means 09:00 on the local wall clock every day, in summer and in winter. It is a time of day with no date and no zone. The store's zone is a property of the store, stored separately, and combined with a date only when we need a specific moment.
4A Log Timestamp: Instant
A log entry records when something happened, as a moment that must be comparable across servers in different regions. Instant is exactly that: a point on the UTC timeline with no zone and no calendar. Two Instants can always be ordered, and Duration.between gives the exact time between them.
For display, a log viewer converts the Instant to the reader's zone, but the stored value stays in UTC.
5A Meeting in New York Next Month: ZonedDateTime
A meeting at 09:00 New York time on 10 December is defined by the local clock in New York. The offset that applies depends on the date: New York is -05:00 in December and -04:00 in summer, and the rules come from the time zone database. ZonedDateTime with ZoneId America/New_York applies those rules for the date we give, and keeps the meeting at 09:00 local time even if we move it across a DST change.
Notice the last line: after the spring clock change, the offset moved to -04:00, but the meeting stayed at 09:00, which is what the attendees expect. A fixed offset or an Instant would have shifted the meeting to 10:00 local time.
6An API Field With an Offset: OffsetDateTime
Many APIs exchange ISO-8601 timestamps with an offset, such as 2026-11-04T10:15:30+02:00. The value identifies an exact moment and records the offset the sender used, without claiming to know the sender's zone rules. OffsetDateTime represents exactly that, and it maps cleanly to JSON and to SQL's TIMESTAMP WITH TIME ZONE columns through JDBC.
| Value | Type | Why |
|---|---|---|
| Birthday | LocalDate | calendar date; no time, no zone |
| Store opening time | LocalTime | wall-clock time every day |
| Log timestamp | Instant | exact moment, comparable across servers |
| Meeting in New York next month | ZonedDateTime + America/New_York | local time with DST rules for that date |
| API field with offset | OffsetDateTime | exact moment plus the sender's fixed offset |
| Length of a call | Duration | seconds and nanoseconds |
| Subscription term | Period | years, months and days |
7Follow-up questions
Why is LocalDateTime a poor choice for the log timestamp?
Because it has no zone or offset, so it does not identify a moment. A LocalDateTime of 2026-11-01T01:30 written by a server in New York happened twice that night, once before and once after the clocks went back, so the log order becomes ambiguous. Servers in different regions, or a server whose default zone changes, would write values that cannot be compared. Instant has none of these problems.
When is LocalDateTime the right type?
When we genuinely mean a wall-clock date and time without a place, or when the zone is stored separately. An example is a recurring local alarm, or a column holding a hotel's local check-in time next to a zone column. It should not be used for moments that already happened.
Why not use OffsetDateTime for the New York meeting?
A fixed offset does not know DST rules. If we store the meeting as -05:00 and later move it to April, the offset stays -05:00 and the meeting lands at 10:00 New York time. A ZonedDateTime recomputes the offset for each date from the zone rules.
8Conclusion
In this answer, we saw that java.time separates local values from points in time. A birthday is a LocalDate and a daily opening time is a LocalTime, because neither belongs to a zone. A log timestamp is an Instant, an exact moment comparable across servers. A future meeting in New York is a ZonedDateTime with America/New_York, so DST rules decide the offset for its date and keep it at the same local time. An API field carrying a fixed offset is an OffsetDateTime. All of these types are immutable and thread-safe.
Open with
java.time splits values into local ones, which describe a calendar or wall clock, and ones that pin down a moment. For a birthday I would use LocalDate, because it is a calendar date that should not shift with time zones; storing it as a timestamp is how birthdays end up a day early for users in another zone.
Then, if they want more
A store's opening time is a LocalTime, nine o'clock on the local clock every day, with the store's zone kept separately. A log timestamp is an Instant, a point on the UTC timeline, because logs from servers in different regions must be comparable and ordered; LocalDateTime would be ambiguous, for example during the hour that repeats when clocks go back.
A meeting in New York next month is a ZonedDateTime with ZoneId America/New_York, because the offset depends on the date: it is minus five in December and minus four in summer, and if we move the meeting across a DST change it should stay at nine local time, which the zone rules handle and a fixed offset would not.
An API field like 2026-11-04T10:15:30+02:00 is an OffsetDateTime: an exact moment plus the offset the sender used, without claiming zone rules. And all these types are immutable and thread-safe, so they can be shared and kept as constants.
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.
- 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 "Give an overview of the main java.time types and say which one you would use for: a...": https://scrivio-interview-library.netlify.app/java/date-and-time/1fe78d8b86/