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

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

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

Java中 Year 类isAfter()方法用于检查当前 YearMonth 对象是否在指定为此方法参数的 YearMonth 之后。

语法

public boolean isAfter(Year otherYearMonth)

参数:它接受一个参数otherYearMonth与当前 YearMonth 对象进行比较。

返回值:如果此 YearMonth 对象的值在指定为方法参数的 YearMonth 对象的值之后,则返回布尔True 值,否则返回 False。

下面的程序说明了Java中的 YearMonth.isAfter() 方法:

程序 1

// Program to illustrate the isAfter() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create first Year object
        YearMonth yearMonth1
            = YearMonth.of(2018, 3);
  
        // Create second Year object
        YearMonth yearMonth2
            = YearMonth.of(1997, 4);
  
        // Check if this year-month object's value is
        // after the specified Year-month or not
        System.out.println(yearMonth1
                               .isAfter(yearMonth2));
    }
}

方案二

// Program to illustrate the isAfter() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create first Year object
        YearMonth yearMonth1
            = YearMonth.of(1997, 3);
  
        // Create second Year object
        YearMonth yearMonth2
            = YearMonth.of(2018, 4);
  
        // Check if this year-month object's value is
        // after the specified Year-month or not
        System.out.println(yearMonth1
                               .isAfter(yearMonth2));
    }
}

参考:https: Java/time/YearMonth.html#isAfter-java.time.YearMonth-