Java Date Time - LocalDate compareTo(ChronoLocalDate other) example








LocalDate compareTo(ChronoLocalDate other) compares this date to another date.

Syntax

compareTo has the following syntax.

public int compareTo(ChronoLocalDate other)

Example

The following example shows how to use compareTo.

import java.time.LocalDate;
/*from  ww  w.j a  v a2 s  . co m*/
public class Main {
  public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = LocalDate.of(2014, 7, 1);
    System.out.println(a.compareTo(b)); 
    System.out.println(a.compareTo(a)); 
    System.out.println(b.compareTo(a)); 
  }
}

The code above generates the following result.