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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。