In Java, start.until(end, unit) returns the number of complete units between two date-times, as a long. For example, between 10:30 on Sunday and 14:45 on Tuesday there are 52 complete hours, even though the real gap is a quarter of an hour longer.
The end is not included, and a partial unit is dropped, not rounded. The same result comes from ChronoUnit.HOURS.between(start, end).
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file. It comes from Temporal, which LocalDateTime implements.
Syntax
Call it on the start and pass the end and a ChronoUnit.
Java
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime end = LocalDateTime.of(2026, 3, 17, 14, 45);
long hours = start.until(end, ChronoUnit.HOURS); // 52
long days = start.until(end, ChronoUnit.DAYS); // 2
Call
What it does
start.until(end, unit)
The number of complete units from start to end.
unit.between(start, end)
The same result, written the other way around.
Duration.between(start, end)
The exact gap as a Duration, in hours, minutes, and seconds.
Period.between(startDate, endDate)
The gap as years, months, and days between two dates.
If end is before start, the result is negative.
Library declarations
Java
// java.time.LocalDateTime
public long until(Temporal endExclusive, TemporalUnit unit)
Parameters
Parameter
Description
endExclusive (Temporal)
The end date-time. It is converted to a LocalDateTime, so it must have a date and a time.
unit (TemporalUnit)
The unit to count in, such as ChronoUnit.DAYS or ChronoUnit.MINUTES.
Return Value
Return Value
Description
long
The number of complete units. Negative if the end is before the start.
31 January to 1 March. Both are at noon, so no time of day gets in the way.
1 full month. One month has passed, but a second month from 31 January would only be complete at the end of March, so it is not counted.
29 days. From 31 January to 28 February is 28 days, and one more day reaches 1 March. February 2026 has 28 days.
Swap the dates. Asking from the later date to the earlier one gives -29, the same number with a minus sign.
Frequently Asked Questions
Use start.until(end, ChronoUnit.HOURS), or ChronoUnit.HOURS.between(start, end). For an exact gap use Duration.between(start, end).
Neither. It drops the incomplete part, so 23 hours 59 minutes is 0 days.
The result is negative, for example -29 days.
until() gives one number in the unit you choose, cut to whole units. Duration.between() gives the full gap in hours, minutes, seconds, and nanoseconds.
Use Period.between(startDate, endDate) with two LocalDate values, for example Period.between(start.toLocalDate(), end.toLocalDate()).