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-
相关用法
- Java Year isAfter()用法及代码示例
- Java OffsetDateTime isAfter()用法及代码示例
- Java LocalDateTime isAfter()用法及代码示例
- Java LocalDate isAfter()用法及代码示例
- Java OffsetTime isAfter()用法及代码示例
- Java ChronoLocalDateTime isAfter()用法及代码示例
- Java ChronoLocalDate isAfter()用法及代码示例
- Java ChronoZonedDateTime isAfter()用法及代码示例
- Java MonthDay isAfter()用法及代码示例
- Java LocalTime isAfter()用法及代码示例
- Java Instant isAfter()用法及代码示例
- Java YearMonth with()用法及代码示例
- Java YearMonth until()用法及代码示例
- Java YearMonth isLeapYear()用法及代码示例
- Java YearMonth range()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 YearMonth isAfter() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。