YearMonth compareTo(YearMonth other) example

Description

YearMonth compareTo(YearMonth other) compares this year-month to another year-month.

Syntax

compareTo has the following syntax.


public int compareTo(YearMonth other)

Example

The following example shows how to use compareTo.


import java.time.YearMonth;
/*w ww. java  2 s  . c  om*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    System.out.println(y.compareTo(YearMonth.now()));

  }
}

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