Dates and times in Java have evolved significantly over the years. Here’s how the main types stack up, why the newer java.time API was needed, and when to use each.


java.util.Date & java.sql.Timestamp


The Modern java.time API (Java 8+)

Designed by the team behind Joda-Time, this API fixes the pain points of the old classes. All types are immutable, thread-safe, and clearly modeled.


LocalDate

LocalTime

LocalDateTime

ZonedDateTime & OffsetDateTime

Instant

Duration & Period

Why the New API?

  1. Clarity – Clear separation of date-only vs. time-only vs. combined vs. zoned types.
  2. Immutability – Thread-safe by design, no surprises from shared mutable state.
  3. Fluent API – Methods like plusDays(), withMonth(), or truncatedTo() make transformations easy to read.
  4. Interoperability – Built-in converters to/from legacy types (Date, Calendar, Timestamp).
  5. Powerful Parsing/FormattingDateTimeFormatter with ISO standards and custom patterns.

By choosing the right type—LocalDate for dates, LocalTime for times, ZonedDateTime for zone-aware moments, and Duration/Period for spans—you’ll write code that’s clearer, safer, and less error-prone.


Classes
Quiz
Videos
References
Books