ChronoLocalDate until(ChronoLocalDate) Method in Java with Examples

until() method of the ChronoLocalDate interface used to get the difference between this Local date and another date passed as a parameter and return the difference in term of ChronoPeriod object. This operation is performed in terms of years, months and days and return the answer in same. The start point is this ChronoLocalDate and the endpoint is the specified date passed as a parameter. when the start point is the after in term of date than the endpoint then the return value is negative.ISO calender is very important for this method because the calculation is performed using the ISO calendar system.

Syntax:

public ChronoPeriod until(ChronoLocalDate endDateExclusive)

Parameters: This method accepts one parameter endDateExclusive which is the end date, exclusive, which may be in any chronology, It should not be null.



Return value: This method returns the period between this date and the end date.

Below programs illustrate the until() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ChronoLocalDate.until() method
  
import java.time.*;
import java.time.temporal.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create ChronoLocalDate objects
        ChronoLocalDate l1
            = LocalDate
                  .parse("2018-12-06");
  
        ChronoLocalDate l2
            = LocalDate
                  .parse("2018-10-25");
  
        // apply until the method of LocalDate class
        ChronoPeriod result
            = l2.until(l1);
  
        // print results
        System.out.println("Result in Period: "
                           + result);
    }
}

chevron_right


Output:

Result in Period: P1M11D

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ChronoLocalDate.until() method
  
import java.time.*;
import java.time.temporal.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create ChronoLocalDate objects
        ChronoLocalDate l1
            = LocalDate
                  .parse("2018-12-06");
  
        ChronoLocalDate l2
            = LocalDate
                  .parse("2018-12-15");
  
        // apply until()
        ChronoPeriod result
            = l2.until(l1);
  
        // print results
        System.out.println("Result in Period: "
                           + result);
    }
}

chevron_right


Output:

Result in Period: P-9D

References: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#until-java.time.chrono.ChronoLocalDate-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.