- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 期間
- java.time - 瞬時
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 期
- java.time - 年
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - 月
- java.time 有用資源
- java.time - 討論
java.time.MonthDay.compareTo() 方法示例
說明
java.time.MonthDay.compareTo(MonthDay other) 方法將此月日與另一個月日進行比較。
宣告
以下是 java.time.MonthDay.compareTo(MonthDay other) 方法的宣告。
public int compareTo(MonthDay other)
public int compareTo(MonthDay other)
引數
other - 要比較的另一個月日,不能為空。
返回值
比較器值,如果較小,則為負數;如果較大,則為正數。
異常
NullPointerException - 其他為 null。
示例
package com.tutorialspoint;
import java.time.MonthDay;
public class MonthDayDemo {
public static void main(String[] args) {
MonthDay date = MonthDay.parse("--12-30");
System.out.println(date);
MonthDay date1 = MonthDay.parse("--12-20");
System.out.println(date1);
System.out.println(date1.compareTo(date));
}
}
即時演示
--12-30 --12-20 -10
列印頁面