Calculates the amount of time until another time in terms of the specified unit.
This calculates the amount of time between two OffsetTime objects in terms of a single TemporalUnit. The start and end points are this and the specified time. The result will be negative if the end is before the start. For example, the amount in hours between two times can be calculated using startTime.until(endTime, HOURS) .
The Temporal passed to this method is converted to a OffsetTime using from(TemporalAccessor). If the offset differs between the two times, then the specified end time is normalized to have the same offset as this time.
The calculation returns a whole number, representing the number of complete units between the two times. For example, the amount in hours between 11:30Z and 13:29Z 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. The second is to use TemporalUnit.between(Temporal, Temporal) :
// these two lines are equivalent
amount = start.until(end, MINUTES);
amount = MINUTES.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 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.