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
廣告