LocalDate.of()
Creates a date from a year, month and day.
Available since: Java 8
Syntax
static LocalDate of(int year, int month, int dayOfMonth)Parameters
| Parameter | Type | Description |
|---|---|---|
| year | int | The year. |
| month | int / Month | The month from 1 to 12, or a constant such as Month.MARCH. |
| dayOfMonth | int | The day of the month. |
Return value
LocalDateA new date.
Examples
A date and its parts:
void main() {
LocalDate date = LocalDate.of(2025, 3, 14);
IO.println(date);
IO.println(date.getMonth());
IO.println(date.getDayOfYear());
IO.println(date.isLeapYear());
}Output:
2025-03-14
MARCH
73
falseA date that does not exist throws an exception:
void main() {
try {
LocalDate.of(2025, 2, 30);
} catch (DateTimeException e) {
IO.println(e.getMessage());
}
}Output:
Invalid date 'FEBRUARY 30'Notes
Months start at 1, not 0 as in the old java.util.Calendar. Compare dates with isBefore(), isAfter(), isEqual() or equals().
See also
- LocalDate.now() — Returns today's date from the computer's clock and time zone.
- LocalDate.parse() — Parses a date from a string — in ISO format (2025-03-14) or with a pattern.
- LocalDate.plusDays() — Returns a date the given number of days later. Related: minusDays(), plusWeeks(), plusMonths(), plusYears().
Related recipes
In the tutorial
- Dates and times — The java.time package — LocalDate, LocalTime, LocalDateTime, date arithmetic, Period, Duration, ChronoUnit, time zones and Instant.