MonthDay compareTo(MonthDay other) example

Description

MonthDay compareTo(MonthDay other) compares this month-day to another month-day.

Syntax

compareTo has the following syntax.


public int compareTo(MonthDay other)

Example

The following example shows how to use compareTo.


import java.time.Month;
import java.time.MonthDay;
//  w  w  w . j a  va  2  s.  c om
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    
    System.out.println(m.compareTo(MonthDay.of(Month.APRIL, 1)));

  }
}

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