YearMonth until(Temporal endExclusive, TemporalUnit unit) example

Description

YearMonth until(Temporal endExclusive, TemporalUnit unit) calculates the amount of time until another year-month in terms of the specified unit.

Syntax

until has the following syntax.


public long until(Temporal endExclusive,  TemporalUnit unit)

Example

The following example shows how to use until.


import java.time.Month;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
// www. j  a v a2  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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset