LocalDate, LocalTime, and LocalDateTime
Local values: date and time without a time zone
Not every time value should be tied to a specific place on Earth.
A birthday is primarily a calendar date, the start time of a daily stand-up is a time of day,
and “2026-09-18 14:30” may describe a local schedule if the time zone is stored separately or is not needed at all.
For such cases, java.time provides three core classes.
LocalDate— a date without a time or time zone;LocalTime— a time of day without a date or time zone;LocalDateTime— a date and time together, but still without a time zone.
LocalDate date = LocalDate.of(2026, 9, 18);
LocalTime time = LocalTime.of(14, 30);
LocalDateTime lesson = LocalDateTime.of(date, time);
Here, lesson means “September 18, 2026 at 14:30,”
but it does not tell us what instant that is in Yerevan, Berlin, or Tokyo.
That is not a limitation of the class; it is its meaning.
Creating and reading values
Values are most often created with of(), current values are obtained with
now(), or standard ISO text is parsed with parse().
The required components can be read with regular methods.
LocalDate date = LocalDate.parse("2026-09-18");
int year = date.getYear();
Month month = date.getMonth();
DayOfWeek day = date.getDayOfWeek();
The classes validate their values. For example,
LocalDate.of(2026, 2, 30) will not create a “strange” date;
it will throw a DateTimeException.
Objects are immutable
The java.time classes are immutable: an operation does not rewrite the existing object,
but returns a new one. This is especially important to notice in code that uses plus...,
minus..., and with... methods.
LocalDate today = LocalDate.of(2026, 9, 18);
today.plusDays(1);
System.out.println(today); // 2026-09-18
To keep the result, you need to assign it:
LocalDate tomorrow = today.plusDays(1);