次の方法で共有


ITemporalField.AdjustInto(Object, Int64) Method

Definition

Returns a copy of the specified temporal object with the value of this field set.

[Android.Runtime.Register("adjustInto", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAdjustInto_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalFieldInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "R extends java.time.temporal.Temporal" })]
public Java.Lang.Object? AdjustInto (Java.Lang.Object? temporal, long newValue);
[<Android.Runtime.Register("adjustInto", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAdjustInto_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalFieldInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "R extends java.time.temporal.Temporal" })>]
abstract member AdjustInto : Java.Lang.Object * int64 -> Java.Lang.Object

Parameters

temporal
Object

the temporal object to adjust, not null

newValue
Int64

the new value of the field

Returns

the adjusted temporal object, not null

Attributes

Remarks

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.

Java documentation for java.time.temporal.TemporalField.adjustInto(R, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to