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
列印頁面
© . All rights reserved.