java.time.MonthDay.compareTo(MonthDay other)
方法將此月-日與另一個月-日進行比較。
聲明
以下是java.time.MonthDay.compareTo(MonthDay other)
方法的聲明。
public int compareTo(MonthDay other)
參數
other
- 比較的其他月份日,不能為null
。
返回值
比較器值,如果小則為負,如果大則為正。
異常
NullPointerException
- 另一個為null
。
示例
以下示例顯示了java.time.MonthDay.compareTo(MonthDay other)
方法的用法。
package com.zaixian;
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
上一篇:
java.time.MonthDay類
下一篇:
java.time.OffsetDateTime類