當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java MonthDay isAfter()用法及代碼示例


MonthDay類的isAfter()方法用於檢查此MonthDay是否在作為參數傳遞的MonthDay之後。此方法返回一個顯示相同值的布爾值。

用法:

public boolean isAfter(MonthDay other)

參數:此方法接受一個參數,另一個與另一個month-day進行比較。


返回值:如果此MonthDay在指定的MonthDay之後,則此方法返回true,否則返回false。

以下示例程序旨在說明isAfter()方法:
示例1:

// Java program to demonstrate 
// MonthDay.isAfter() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // create a MonthDay object 
        MonthDay month = MonthDay.parse("--10-12"); 
  
        // create other MonthDay object 
        MonthDay othermonth = MonthDay.parse("--11-12"); 
  
        // apply isAfter() method 
        boolean value = month.isAfter(othermonth); 
  
        // print instance 
        System.out.println("monthday:"
                           + month + " is after monthday:"
                           + othermonth + " = "
                           + value); 
    } 
}
輸出:
monthday:--10-12 is after monthday:--11-12 = false

示例2:

// Java program to demonstrate 
// MonthDay.isAfter() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // create a MonthDay object 
        MonthDay month = MonthDay.parse("--10-12"); 
  
        // create other MonthDay object 
        MonthDay othermonth = MonthDay.parse("--09-12"); 
  
        // apply isAfter() method 
        boolean value = month.isAfter(othermonth); 
  
        // print instance 
        System.out.println("monthday:"
                           + month + " is after monthday:"
                           + othermonth + " = "
                           + value); 
    } 
}
輸出:
monthday:--10-12 is after monthday:--09-12 = true

參考文獻: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#isAfter(java.time.MonthDay)



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 MonthDay isAfter() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。