Java Date Time - Year until(Temporal endExclusive, TemporalUnit unit) example








Year until(Temporal endExclusive, TemporalUnit unit) calculates the amount of time until another year 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.Year;
import java.time.temporal.ChronoUnit;
// w ww.j a  v  a 2 s.  co  m
public class Main {
  public static void main(String[] args) {
    Year y = Year.of(2014);
    long l = y.until(Year.of(2000),ChronoUnit.YEARS);
    System.out.println(l);

  }
}

The code above generates the following result.