📌  相关文章
📜  Java中的 MonthDay isAfter() 方法及示例

📅  最后修改于: 2022-05-13 01:55:38.233000             🧑  作者: Mango

Java中的 MonthDay isAfter() 方法及示例

MonthDay类的isAfter()方法用于检查此 MonthDay 是否在作为参数传递的 MonthDay 之后。此方法返回一个布尔值,显示相同。

句法:

public boolean isAfter(MonthDay other)

参数:此方法接受一个参数, other是要比较的另一个月份。

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

下面的程序说明了 isAfter() 方法:
方案一:

// 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

方案二:

// 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: Java Java.time.MonthDay)