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


Java MonthDay isBefore()用法及代码示例


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

用法:

public boolean isBefore(MonthDay other)

参数:此方法接受一个参数,另一个与另一个month-day进行比较。


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

以下示例程序旨在说明isBefore()方法:
示例1:

// Java program to demonstrate 
// MonthDay.isBefore() 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 isBefore() method 
        boolean value = month.isBefore(othermonth); 
  
        // print instance 
        System.out.println("monthday:"
                           + month + " is before monthday:"
                           + othermonth + " = "
                           + value); 
    } 
}
输出:
monthday:--10-12 is before monthday:--11-12 = true

示例2:

// Java program to demonstrate 
// MonthDay.isBefore() 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 isBefore() method 
        boolean value = month.isBefore(othermonth); 
  
        // print instance 
        System.out.println("monthday:"
                           + month + " is before monthday:"
                           + othermonth + " = "
                           + value); 
    } 
}
输出:
monthday:--10-12 is before monthday:--09-12 = false

参考文献: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#isBefore(java.time.MonthDay)



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 MonthDay isBefore() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。