
- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 瞬時
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - 區域日期時間
- java.time - 區域識別符號
- java.time - 區域偏移量
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.YearMonth.compareTo() 方法示例
說明
java.time.YearMonth.compareTo(YearMonth other) 方法將此年月與另一年月進行比較。
宣告
以下是 java.time.YearMonth.compareTo(YearMonth other) 方法的宣告。
public int compareTo(YearMonth other)
引數
other - 要比較的另一個年月,不能為空。
返回值
比較器值,小於則為負數,大於則為正數。
示例
以下示例展示了 java.time.YearMonth.compareTo(YearMonth other) 方法的使用。
package com.tutorialspoint; import java.time.YearMonth; public class YearMonthDemo { public static void main(String[] args) { YearMonth date = YearMonth.of(2005,11); YearMonth date1 = YearMonth.of(2006,11); System.out.println(date.compareTo(date1)); } }
編譯並執行以上程式,結果如下:
-1
廣告