LocalDate until(Temporal endExclusive, TemporalUnit unit)
calculates the
amount of time until another date in terms of the specified unit.
The units DAYS, WEEKS, MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.
until
has the following syntax.
public long until(Temporal endExclusive, TemporalUnit unit)
The following example shows how to use until
.
import java.time.LocalDate; import java.time.temporal.ChronoUnit; //from w w w . j a v a2 s.com public class Main { public static void main(String[] args) { LocalDate a = LocalDate.of(2014, 6, 30); long p = a.until(LocalDate.of(2015, 6, 30), ChronoUnit.MONTHS); System.out.println(p); } }
The code above generates the following result.