QuickDevGuide

Home › Java

Date & Time API — Java

The java.time package (Java 8+) replaced the error-prone Date and Calendar. All classes are immutable and thread-safe. Class Represents Example LocalDate date without time zone birthday 2026-10-25 LocalTime time of day opening hours 09:00 LocalDateTime date + time, no zone a meeting in "local" terms ZonedDateTime date + time + zone (DST-aware) flight departure in Europe/Paris Instant a point on the UTC timeline timestamps, logs, DB columns Duration time-based amount (h/m/s) timeout of 30 seconds Period date-based amount (y/m/d) subscription of 1 month DateTimeFormatter parsing & formatting "dd MMM yyyy" Best practices Store and transmit Instant/UTC; convert to a ZonedDateTime only for display. Inject a Clock into services so tests can control "now".

Key Takeaways