java.time.Year.isBefore() 方法示例



說明

java.time.Year.isBefore(Year other) 方法檢查此年是否早於指定年。

宣告

以下是 java.time.Year.isBefore(Year other) 方法的宣告。

public boolean isBefore(Year other)

引數

other − 要比較的另一個年,非空。

返回值

如果此年早於指定年,則返回 true。

示例

以下示例顯示了 java.time.Year.isBefore(Year other) 方法的用法。

package com.tutorialspoint;

import java.time.Year;

public class YearDemo {
   public static void main(String[] args) {
 
      Year date = Year.of(2016);
      Year date1 = Year.of(2017);
      System.out.println(date1.isBefore(date));  
   }
}

讓我們編譯並執行上述程式,這將產生以下結果 −

false
廣告
© . All rights reserved.