Share via


ITemporalUnit.Between(ITemporal, ITemporal) Method

Definition

Calculates the amount of time between two temporal objects.

[Android.Runtime.Register("between", "(Ljava/time/temporal/Temporal;Ljava/time/temporal/Temporal;)J", "GetBetween_Ljava_time_temporal_Temporal_Ljava_time_temporal_Temporal_Handler:Java.Time.Temporal.ITemporalUnitInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
public long Between (Java.Time.Temporal.ITemporal? temporal1Inclusive, Java.Time.Temporal.ITemporal? temporal2Exclusive);
[<Android.Runtime.Register("between", "(Ljava/time/temporal/Temporal;Ljava/time/temporal/Temporal;)J", "GetBetween_Ljava_time_temporal_Temporal_Ljava_time_temporal_Temporal_Handler:Java.Time.Temporal.ITemporalUnitInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
abstract member Between : Java.Time.Temporal.ITemporal * Java.Time.Temporal.ITemporal -> int64

Parameters

temporal1Inclusive
ITemporal

the base temporal object, not null

temporal2Exclusive
ITemporal

the other temporal object, exclusive, not null

Returns

the amount of time between temporal1Inclusive and temporal2Exclusive in terms of this unit; positive if temporal2Exclusive is later than temporal1Inclusive, negative if earlier

Attributes

Remarks

Calculates the amount of time between two temporal objects.

This calculates the amount in terms of this unit. The start and end points are supplied as temporal objects and must be of compatible types. The implementation will convert the second type to be an instance of the first type before the calculating the amount. The result will be negative if the end is before the start. For example, the amount in hours between two temporal objects can be calculated using HOURS.between(startTime, endTime).

The calculation returns a whole number, representing the number of complete units between the two temporals. For example, the amount in hours between the times 11:30 and 13:29 will only be one hour as it is one minute short of two hours.

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

// these two lines are equivalent
              between = thisUnit.between(start, end);
              between = start.until(end, thisUnit);

The choice should be made based on which makes the code more readable.

For example, this method allows the number of days between two dates to be calculated:

long daysBetween = DAYS.between(start, end);
             // or alternatively
             long daysBetween = start.until(end, DAYS);

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 objects.

Java documentation for java.time.temporal.TemporalUnit.between(java.time.temporal.Temporal, java.time.temporal.Temporal).

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