Language

OffsetDateTime.Until(ITemporal, ITemporalUnit) Method

Definition

Calculates the amount of time until another date-time in terms of the specified unit.

[Android.Runtime.Register("until", "(Ljava/time/temporal/Temporal;Ljava/time/temporal/TemporalUnit;)J", "", ApiSince=26)]
public long Until(Java.Time.Temporal.ITemporal? endExclusive, Java.Time.Temporal.ITemporalUnit? unit);
[<Android.Runtime.Register("until", "(Ljava/time/temporal/Temporal;Ljava/time/temporal/TemporalUnit;)J", "", ApiSince=26)>]
abstract member Until : Java.Time.Temporal.ITemporal * Java.Time.Temporal.ITemporalUnit -> int64
override this.Until : Java.Time.Temporal.ITemporal * Java.Time.Temporal.ITemporalUnit -> int64

Parameters

endExclusive
ITemporal

the end date, exclusive, which is converted to an OffsetDateTime, not null

unit
ITemporalUnit

the unit to measure the amount in, not null

Returns

the amount of time between this date-time and the end date-time

Implements

Attributes

Remarks

Calculates the amount of time until another date-time in terms of the specified unit. The Temporal passed to this method is converted to an OffsetDateTime using from(TemporalAccessor). For a ChronoUnit, if the offsets differ, the end is normally converted to the start's offset. If that conversion exceeds the supported date range, Android releases 8.0 through 13 throw a DateTimeException. In Android releases 14 through 17 and the SDK 37.2 source, the method instead tries to convert the start to the end's offset, which can also exceed the supported range. For other units, the converted end is passed to the unit without this offset normalization. For a supported ChronoUnit, the calculation returns the number of complete units between the date-times. For example, the amount in months between 2012-06-15T00:00Z and 2012-08-14T23:59Z is one month. For a supported ChronoUnit, these calls are equivalent:

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

The choice should be made based on which makes the code more readable. The calculation is implemented in this method for ChronoUnit. The units NANOS, MICROS, MILLIS, SECONDS, MINUTES, HOURS and HALF_DAYS, DAYS, WEEKS, MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception. If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal) passing this as the first argument and the converted input temporal as the second argument. This instance is immutable and unaffected by this method call.

Java reference for java.time.OffsetDateTime.until.

Applies to