YearMonth until(Temporal endExclusive, TemporalUnit unit)
calculates the amount of time until another year-month in terms of the specified unit.
until
has the following syntax.
public long until(Temporal endExclusive, TemporalUnit unit)
The following example shows how to use until
.
import java.time.Month; import java.time.YearMonth; import java.time.temporal.ChronoUnit; /*from w w w . jav a 2 s . c o m*/ public class Main { public static void main(String[] args) { YearMonth y = YearMonth.now(); long s = y.until(YearMonth.of(1990, Month.JANUARY),ChronoUnit.YEARS); System.out.println(s); } }
The code above generates the following result.