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








ZonedDateTime until(Temporal endExclusive, TemporalUnit unit) calculates the amount of time until another date-time 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.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/*from w ww  . j  av a  2 s.  co m*/
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    long o =  dateTime.until(ZonedDateTime.now(),ChronoUnit.YEARS);
    System.out.println(o);
  } 
}

The code above generates the following result.