Java中Year類的isBefore()方法用於檢查當前的YearMonth對象是否在指定為該方法的參數YearMonth之前。
用法:
public boolean isBefore(Year otherYearMonth)
參數:它接受單個參數otherYearMonth,它將與當前YearMonth對象進行比較。
返回值:如果此YearMonth對象的值在指定為方法參數的YearMonth對象的值之前,則返回布爾True值,否則返回False。
以下程序說明了Java中的YearMonth.isBefore()方法:
示例1::
// Program to illustrate the isBefore() 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
// before the specified Year-month or not
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
輸出:
false
示例2::
// Program to illustrate the isBefore() 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
// before the specified Year-month or not
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
輸出:
true
參考: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isBefore-java.time.YearMonth-
相關用法
- Java OffsetDateTime isBefore()用法及代碼示例
- Java LocalTime isBefore()用法及代碼示例
- Java LocalDate isBefore()用法及代碼示例
- Java LocalDateTime isBefore()用法及代碼示例
- Java OffsetTime isBefore()用法及代碼示例
- Java ChronoLocalDate isBefore()用法及代碼示例
- Java ChronoZonedDateTime isBefore()用法及代碼示例
- Java Year isBefore()用法及代碼示例
- Java Instant isBefore()用法及代碼示例
- Java ChronoLocalDateTime isBefore()用法及代碼示例
- Java MonthDay isBefore()用法及代碼示例
- Java YearMonth until()用法及代碼示例
- Java YearMonth with()用法及代碼示例
- Java YearMonth withYear()用法及代碼示例
- Java YearMonth range()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 YearMonth isBefore() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。