Temporal (Java Platform SE 8 ) (original) (raw)
Calculates the amount of time until another temporal in terms of the specified unit.
This calculates the amount of time between two temporal objects in terms of a single TemporalUnit
. The start and end points are this
and the specified temporal. The end point is converted to be of the same type as the start point if different. 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 startTime.until(endTime, HOURS)
.
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 TemporalUnit.between(Temporal, Temporal):
// these two lines are equivalent temporal = start.until(end, unit); temporal = unit.between(start, end);
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 = start.until(end, DAYS); // or alternatively long daysBetween = DAYS.between(start, end);