当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。