Compartilhar via


ITemporalUnit.AddTo(Object, Int64) Method

Definition

Returns a copy of the specified temporal object with the specified period added.

[Android.Runtime.Register("addTo", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAddTo_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalUnitInvoker, 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? AddTo (Java.Lang.Object? temporal, long amount);
[<Android.Runtime.Register("addTo", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAddTo_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalUnitInvoker, 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 AddTo : Java.Lang.Object * int64 -> Java.Lang.Object

Parameters

temporal
Object

the temporal object to adjust, not null

amount
Int64

the amount of this unit to add, positive or negative

Returns

the adjusted temporal object, not null

Attributes

Remarks

Returns a copy of the specified temporal object with the specified period added.

The period added is a multiple of this unit. For example, this method could be used to add "3 days" to a date by calling this method on the instance representing "days", passing the date and the period "3". The period to be added may be negative, which is equivalent to subtraction.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use Temporal#plus(long, TemporalUnit):

// these two lines are equivalent, but the second approach is recommended
              temporal = thisUnit.addTo(temporal);
              temporal = temporal.plus(thisUnit);

It is recommended to use the second approach, plus(TemporalUnit), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the units available in ChronoUnit or the fields available in ChronoField. If the unit 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.TemporalUnit.addTo(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