LocalDate, LocalTime and LocalDateTime are immutable date and time classes from the java.time package, added in Java 8. LocalDate holds a date (year, month, day), LocalTime holds a time of day, and LocalDateTime holds both, and none of them has a time zone or offset.
They replace most uses of java.util.Date and Calendar. Use them for values that are the same wall-clock reading everywhere, such as a birthday or a shop opening time, and use ZonedDateTime or Instant for moments on the global timeline.
| Class | Holds | Example value | Typical use |
|---|---|---|---|
LocalDate | Date only | 2026-11-17 | Birthdays, holidays, due dates |
LocalTime | Time only | 14:30:15 | Opening hours, alarms |
LocalDateTime | Date and time | 2026-11-17T14:30:15 | Local appointments, log fields |
All of them are immutable and thread safe, follow ISO-8601, and are value-based classes, so compare them with equals or isBefore/isAfter, never with ==.
Every "modifying" method such as plusDays returns a new object and leaves the original unchanged, so you must use the returned value. Invalid dates such as LocalDate.of(2026, 2, 30) throw DateTimeException.
LocalTime wraps around midnight: LocalTime.of(23, 0).plusHours(2) gives 01:00, with no date carried over. If you need to cross midnight with a date, use LocalDateTime.
LocalDateTime is not an instant on the timeline. To turn it into one you must supply a zone or offset with atZone or atOffset. Daylight saving time can make a local time nonexistent or ambiguous, and ZonedDateTime resolves those cases for you.
DateTimeFormatter is thread safe and can be stored in a static final field, unlike the old SimpleDateFormat. Note the case sensitive letters: MM is month, mm is minute, HH is hour of day and yyyy is the year. For locale-aware output use DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).
Use Period for date based amounts and Duration for time based amounts, or ChronoUnit for a single unit.
JDBC 4.2 and later and JPA 2.2 and later support these types directly, so map them to DATE, TIME and TIMESTAMP columns with rs.getObject("created", LocalDateTime.class). For testability, inject a Clock and call LocalDate.now(clock) rather than now().
Use LocalDateTime for values that are tied to a place's wall clock, such as a scheduled local appointment. Use ZonedDateTime, OffsetDateTime or Instant for exact moments, such as event timestamps stored in a database.
Use date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(). For java.sql.Date, call toLocalDate().
Call ChronoUnit.DAYS.between(start, end). The result is negative if end is before start.
Yes. They are immutable, so instances can be shared between threads without synchronisation.
LocalDate, LocalTime and LocalDateTime model dates and times without a time zone. They are immutable, use ISO-8601, and offer fluent methods for arithmetic, comparison, formatting and parsing. Choose them for wall-clock values, switch to ZonedDateTime or Instant when you need an exact moment, and prefer java.time over Date, Calendar and SimpleDateFormat in all new code.