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.