Year類的isSupported(TemporalField)方法用於檢查Year類是否支持指定的字段,這意味著使用此方法,我們可以檢查是否可以為指定的字段查詢Year對象。
ChronoField支持的字段是:
- YEAR_OF_ERA
- 年
- 時代
所有其他ChronoField實例將返回false。
用法:
public boolean isSupported(TemporalField field)
參數:領域代表要檢查的字段。
返回值:如果此Year支持此字段,則此方法返回布爾值true,否則返回false。
以下示例程序旨在說明isSupported(TemporalField)方法:
示例1:
// Java program to demonstrate
// Year.isSupported(TemporalField) method
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
// create a Year object
Year year = Year.of(2019);
// print instance
System.out.println("Year :"
+ year);
// apply isSupported() method
boolean value
= year.isSupported(
ChronoField.YEAR_OF_ERA);
// print result
System.out.println("YEAR_OF_ERA Field is supported by Year class: "
+ value);
}
}
輸出:
Year :2019 YEAR_OF_ERA Field is supported by Year class: true
示例2:
// Java program to demonstrate
// Year.isSupported(TemporalField) method
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
// create a Year object
Year year = Year.of(2022);
// print instance
System.out.println("Year :"
+ year);
// apply isSupported() method
boolean value
= year.isSupported(
ChronoField.MILLI_OF_SECOND);
// print result
System.out.println("MiliSecond Field is supported: "
+ value);
}
}
輸出:
Year :2022 MiliSecond Field is supported: false
相關用法
- Java Year now()用法及代碼示例
- Java Year until()用法及代碼示例
- Java Year from()用法及代碼示例
- Java Year with()用法及代碼示例
- Java Year of()用法及代碼示例
- Java Year get()用法及代碼示例
- Java Year minusYears()用法及代碼示例
- Java Year query()用法及代碼示例
- Java Year range()用法及代碼示例
- Java Year length()用法及代碼示例
- Java Year plusYears()用法及代碼示例
- Java Year getLong()用法及代碼示例
- Java Year adjustInto()用法及代碼示例
- Java Year plus(TemporalAmount)用法及代碼示例
- Java Year isLeap()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 Year isSupported(TemporalField) Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。