Java MonthDay isAfter()方法及示例
MonthDay 类的 isAfter() 方法用于检查这个MonthDay是否在作为参数传递的MonthDay之后。该方法返回一个布尔值,显示相同的情况。
语法
public boolean isAfter(MonthDay other)
参数: 该方法接受一个参数 , 即另一个要比较的月日。
返回值: 如果这个月日在指定的月日之后,该方法返回真,否则返回假。
以下程序说明了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)
