Java Date/Time API (java.time) — LocalDate, ZonedDateTime, Duration, Period
Fast recall
Quick revision
Core answer
LocalDate/LocalDateTime = no timezone (local calendar). ZonedDateTime = date+time+zone (use for cross-region logic). Instant = UTC machine timestamp. Duration = time-based gap (hours/seconds). Period = date-based gap (years/months/days). All immutable. LocalDateTime.now() on a server is timezone-naive — use ZonedDateTime. Avoid legacy Date/Calendar — mutable, not thread-safe, months are 0-indexed.Whether the candidate knows when to use LocalDate vs LocalDateTime vs ZonedDateTime, understands immutability, and can explain Duration (time-based) vs Period (date-based) correctly
Using LocalDateTime for timestamps that need timezone context — LocalDateTime has no timezone, so 2pm LocalDateTime could mean 2pm in any timezone. Confusing Duration (hours/minutes/seconds) with Period (years/months/days) — they're not interchangeable
Explain that all java.time classes are immutable and thread-safe — plusDays() returns a new object. Mention the DST trap: adding 24 hours with Duration vs 1 day with Period gives different results during DST transitions. Know that Instant is the correct type for machine timestamps
Interview-ready guide
Interview answer
java.time replaced Date and Calendar because those were mutable, not thread-safe, and had confusing design (zero-indexed months, years offset from 1900). Everything in java.time is immutable — plusDays() returns a new object.
Choosing the right type
LocalDate— date only, no time; birthdays, holidays, business datesLocalTime— time only; opening hours, alarm timesLocalDateTime— date + time but no timezone — dangerous for server-side timestamps; "2pm" with no zone is ambiguousZonedDateTime— date + time + zone; use for scheduling and any cross-region eventInstant— UTC seconds since epoch; the correct type for audit logs, database timestamps, cross-timezone comparisons
Duration vs Period
Duration— time-based gap in seconds/nanos;Duration.ofHours(24)adds exactly 24 hoursPeriod— calendar-based gap in years/months/days;Period.ofDays(1)adds one calendar day, keeping the same wall-clock time- During a DST spring-forward, these diverge: adding 24 hours lands at 1am the next day; adding 1 day keeps 2pm
I recommend Instant for storage and database timestamps, and ZonedDateTime only at the display layer where a human-readable timezone is needed.
Java Date/Time API (java.time) — LocalDate, ZonedDateTime, Duration, Period
Direct Answer
LocalDate/LocalDateTime = no timezone (local calendar). ZonedDateTime = date+time+zone (use for cross-region logic). Instant = UTC machine timestamp. Duration = time-based gap (hours/seconds). Period = date-based gap (years/months/days). All immutable. LocalDateTime.now() on a server is timezone-naive — use ZonedDateTime. Avoid legacy Date/Calendar — mutable, not thread-safe, months are 0-indexed.
Common Mistakes & Pitfalls
Using LocalDateTime for timestamps that need timezone context — LocalDateTime has no timezone, so 2pm LocalDateTime could mean 2pm in any timezone. Confusing Duration (hours/minutes/seconds) with Period (years/months/days) — they're not interchangeable
Check your understanding
Answer these without looking back at the article.
- What is the difference between LocalDateTime and ZonedDateTime — when does the distinction matter?
- Why is java.util.Date considered broken — what specific design flaws does java.time fix?
- How do you convert between LocalDateTime and ZonedDateTime?
- What is the difference between Duration and Period — give a scenario where you'd use each?
- What replaced SimpleDateFormat in java.time and how do you parse/format dates with it?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.