Java LocalDate of() Method
Example
Create two fixed dates:
import java.time.LocalDate;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2026, 1, 15);
LocalDate date2 = LocalDate.of(1990, Month.DECEMBER, 15);
System.out.println(date1);
System.out.println(date2);
}
}
Definition and Usage
The of() method creates a LocalDate object from a year, a month and a day of the month.
The month can be a number from 1 (January) to 12 (December), or a Month value like Month.DECEMBER.
Tip: To get today's date, use the now() method.
Syntax
One of the following:
public static LocalDate of(int year, int month, int dayOfMonth)
public static LocalDate of(int year, Month month, int dayOfMonth)
Parameter Values
| Parameter | Description |
|---|---|
| year | Required. The year, for example 2026. |
| month | Required. The month, as a number from 1 to 12, or as a Month value. |
| dayOfMonth | Required. The day of the month, from 1 to 31. |
Technical Details
| Returns: | A LocalDate object with the given date. |
|---|---|
| Throws: | DateTimeException - if a value is out of range, or if the date does not exist (for example February 30). |
Related Pages
❮ Date and Time Methods