OffsetDateTime with(TemporalField field, long newValue) example
Description
OffsetDateTime 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 OffsetDateTime with(TemporalField field, long newValue)
Example
The following example shows how to use with
.
import java.time.OffsetDateTime;
import java.time.temporal.ChronoField;
/* w ww . j av a 2s. co m*/
public class Main {
public static void main(String[] args) {
OffsetDateTime o = OffsetDateTime.now();
OffsetDateTime d = o.with(ChronoField.YEAR,2010);
System.out.println(d);
}
}
The code above generates the following result.