In Java, LocalDateTime.of(...) builds a LocalDateTime from values you choose. The most common version takes the year, month, day, hour, and minute as numbers.
Seconds and nanoseconds are optional extra arguments. You can also pass a Month enum instead of the month number, or pass a LocalDate and a LocalTime together.
A static method of java.time.LocalDateTime (since Java 8): call it on the class, as LocalDateTime.of(), with no object needed. Add import java.time.LocalDateTime; at the top of your file.
Syntax
Call the static method with the values you need. The month is 1 for January.
Java
LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 30); // 2026-03-15T10:30
LocalDateTime b = LocalDateTime.of(2026, 3, 15, 10, 30, 45); // with seconds
LocalDateTime c = LocalDateTime.of(2026, Month.MARCH, 15, 10, 30); // with a Month enum
LocalDateTime d = LocalDateTime.of(LocalDate.of(2026, 3, 15), LocalTime.of(10, 30));
Call
What it does
of(y, m, d, h, min)
Builds a date-time with zero seconds and no fraction.
of(y, m, d, h, min, s)
Adds the second.
of(y, m, d, h, min, s, nano)
Adds the second and the nanosecond.
of(date, time)
Joins a LocalDate and a LocalTime.
Every version also accepts a Month enum in place of the month number (except the one that takes a LocalDate).
Library declarations
Java
// java.time.LocalDateTime
public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute)
public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second)
public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)
public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute)
public static LocalDateTime of(LocalDate date, LocalTime time)
Parameters
Parameter
Description
year (int)
The year, from -999999999 to 999999999.
month (int or Month)
The month: 1 to 12, or a value such as Month.MARCH.
dayOfMonth (int)
The day, from 1 up to the length of that month.
hour, minute (int)
The hour (0 to 23) and the minute (0 to 59).
second, nanoOfSecond (int)
Optional. The second (0 to 59) and the nanosecond (0 to 999,999,999).