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));
}
}
程序2 :
// 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://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isAfter-java.time.YearMonth-