CKTIS / Java
LocalDate — a date without time or time zone
LocalDate represents an immutable ISO calendar date without a time or time zone. It supports creating, shifting, comparing, parsing, and formatting dates.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
LocalDate.of(year, month, dayOfMonth)
date.plusDays(days)
date.isAfter(other)
date.toString()
date.equals(other)
date.compareTo(other)
date.with(adjuster)
date.with(field, newValue)
date.atTime(hour, minute)
LocalDate.parse(text)
LocalDate.parse(text, formatter)
date.format(formatter)java.time.LocalDate stores an ISO calendar date without a time or time zone; alone, it does not identify an instant on the timeline. It is immutable and thread-safe. LocalDate.of(year, month, dayOfMonth) creates a date; months are numbered 1–12. An invalid date causes DateTimeException.
LocalDate.plusDays returns the result of adding days, accounting for month boundaries and leap years; the original remains unchanged. LocalDate.with(adjuster) applies an adjustment rule, while LocalDate.with(field, newValue) sets a field. Invalid-day handling depends on the field: changing the month can clamp the day to the month end, but an invalid DAY_OF_MONTH causes an exception.
LocalDate.isAfter checks whether a date is later. LocalDate.equals compares date values of type LocalDate, not object identity — do not replace it with ==. For two LocalDate objects, LocalDate.compareTo returns a negative number, zero, or a positive number according to date order; do not assume exactly -1 or 1.
LocalDate.parse(text) reads an ISO date; the formatter overload supports another format. A parsing failure causes DateTimeParseException. LocalDate.toString returns ISO text, whereas LocalDate.format(formatter) uses the supplied formatter. In the pattern dd/MM/uuuu, uuuu means year, not year-of-era (yyyy).
LocalDate.atTime(hour, minute) creates a LocalDateTime, still without a time zone; the OffsetTime overload returns OffsetDateTime. The example uses fixed dates and demonstrates February 29, 2024. Documentation scope: Java SE 21; the production runtime is not attested.
Examples
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
public class Main {
public static void main(String[] args) {
LocalDate start = LocalDate.of(2024, 2, 28);
LocalDate next = start.plusDays(1);
LocalDate parsed = LocalDate.parse("2024-02-29");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/uuuu");
System.out.println(start.toString());
System.out.println(next.toString());
System.out.println(next.isAfter(start));
System.out.println(next.equals(parsed));
System.out.println(start.compareTo(next) < 0);
System.out.println(start.with(TemporalAdjusters.lastDayOfMonth()));
System.out.println(next.atTime(9, 30));
System.out.println(next.format(formatter));
}
}Result
2024-02-28 2024-02-29 true true true 2024-02-29 2024-02-29T09:30 29/02/2024
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.