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

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

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

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

句法:

public boolean isBefore(MonthDay other)

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

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

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

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

方案二:

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