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