LocalDate compareTo(ChronoLocalDate other) example

Description

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  va 2s  . com*/
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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset