OffsetDateTime with(TemporalField field, long newValue)
returns a copy of this date-time with the specified field set to a new value.
with
has the following syntax.
public OffsetDateTime with(TemporalField field, long newValue)
The following example shows how to use with
.
import java.time.OffsetDateTime; import java.time.temporal.ChronoField; /* w w w .j a va2 s.c om*/ 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.