LocalDateTime with(TemporalField field, long newValue) example
Description
LocalDateTime with(TemporalField field, long newValue)
returns a copy of this date-time with the specified field set to a new value.
Syntax
with
has the following syntax.
public LocalDateTime with(TemporalField field, long newValue)
Example
The following example shows how to use with
.
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
//w w w. j a va 2s. c o m
public class Main {
public static void main(String[] args) {
LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);
LocalDateTime t = a.with(ChronoField.YEAR,2012);
System.out.println(t);
}
}
The code above generates the following result.