In Java, with(...) returns a new LocalDateTime that is a changed copy of the original. There are two versions. One takes a TemporalAdjuster, a rule such as "go to the last day of the month". The other takes a ChronoField and a value, such as "set the hour to 9".
The class TemporalAdjusters has many ready-made rules, and a LocalDate or a LocalTime can also be used as an adjuster to replace the date or the time part.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file. It comes from Temporal, which LocalDateTime implements.
Syntax
Pass an adjuster, or a field and a value.
Java
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime a = dt.with(TemporalAdjusters.lastDayOfMonth()); // 2026-03-31T10:30
LocalDateTime b = dt.with(TemporalAdjusters.next(DayOfWeek.MONDAY)); // 2026-03-16T10:30
LocalDateTime c = dt.with(ChronoField.HOUR_OF_DAY, 9); // 2026-03-15T09:30
Call
What it does
dt.with(adjuster)
Applies a rule, such as TemporalAdjusters.lastDayOfMonth().
dt.with(field, value)
Sets one ChronoField to a value.
dt.with(LocalDate)
Replaces the date part and keeps the time.
dt.with(LocalTime)
Replaces the time part and keeps the date.
Like every method of LocalDateTime, with() returns a new object and leaves the original unchanged.
Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime with(TemporalAdjuster adjuster)
public LocalDateTime with(TemporalField field, long newValue)
Parameters
Parameter
Description
adjuster (TemporalAdjuster)
A rule such as TemporalAdjusters.firstDayOfMonth(), a LocalDate, or a LocalTime.
field (TemporalField)
The field to set, such as ChronoField.HOUR_OF_DAY. Use with the next argument.
newValue (long)
The new value of the field. It must be inside the range of the field.