0Pricing
Java Academy · Lesson

LocalDate, LocalTime, LocalDateTime

Represent dates and times.

The Modern Date API

Since Java 8 the java.time package replaced the old, error-prone Date and Calendar classes. Its core types are LocalDate, LocalTime, and LocalDateTime.

All of them are immutable and thread-safe.

LocalDate

LocalDate represents a date with no time component: a year, month, and day. LocalDate.now() gives today, but tests should use a fixed date for predictable output.

import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {
        LocalDate date = LocalDate.of(2026, 5, 30);
        System.out.println(date);
    }
}

All lessons in this course

  1. LocalDate, LocalTime, LocalDateTime
  2. Instant and Duration
  3. Period and Date Arithmetic
  4. Formatting with DateTimeFormatter
← Back to Java Academy