Returns a copy of the specified temporal object with the value of this field set.
This returns a new temporal object based on the specified one with the value for this field changed. For example, on a LocalDate
, this could be used to set the year, month or day-of-month. The returned object has the same observable type as the specified object.
In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the implementation is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use Temporal.with(TemporalField, long)
:
// these two lines are equivalent, but the second approach is recommended
temporal = thisField.adjustInto(temporal);
temporal = temporal.with(thisField);
It is recommended to use the second approach,
with(TemporalField)
, as it is a lot clearer to read in code.
Implementations should perform any queries or calculations using the fields available in ChronoField
. If the field is not supported an UnsupportedTemporalTypeException
must be thrown.
Implementations must not alter the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.