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








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.

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.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.