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
- LocalDate, LocalTime, LocalDateTime
- Instant and Duration
- Period and Date Arithmetic
- Formatting with DateTimeFormatter