java.time.chrono.JapaneseDate類的isSupported()方法用於檢查是否支持特定的chrono字段。
用法:
public boolean isSupported(TemporalField field)
參數:此方法接受“時間”字段的類型,以檢查該時間是否與特定日期兼容。
返回值:如果此日期與傳遞的字段兼容,則此方法返回布爾值,否則返回true,否則返回false。
下麵的示例說明了hashCode()方法:
範例1:
// Java program to demonstrate
// isSupported() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// creating and initializing
// JapaneseDate Object
JapaneseDate hidate = JapaneseDate.now();
// checking for the
// given ChronoField
// by using isSupported() method
boolean status = hidate.isSupported(
ChronoField.ERA);
// display the result
if (status)
System.out.println(
"this field is supported");
else
System.out.println(
"this field is not supported");
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
this field is supported
範例2:
// Java program to demonstrate
// isSupported() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// creating and initializing
// JapaneseDate Object
JapaneseDate hidate = JapaneseDate.now();
// checking for the
// given ChronoField
// by using isSupported() method
boolean status = hidate.isSupported(
ChronoField.MICRO_OF_DAY);
// display the result
if (status)
System.out.println(
"this field is supported");
else
System.out.println(
"this field is not supported");
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
this field is not supported
相關用法
- Java JapaneseDate from()用法及代碼示例
- Java JapaneseDate of(int, int, int)用法及代碼示例
- Java JapaneseDate getLong()用法及代碼示例
- Java JapaneseDate getEra()用法及代碼示例
- Java JapaneseDate getChronology()用法及代碼示例
- Java JapaneseDate of(JapaneseEra,int, int, int)用法及代碼示例
- Java JapaneseDate equals()用法及代碼示例
- Java JapaneseDate atTime()用法及代碼示例
- Java JapaneseDate toString()用法及代碼示例
- Java JapaneseDate toEpochDay()用法及代碼示例
- Java JapaneseDate range()用法及代碼示例
- Java JapaneseDate hashCode()用法及代碼示例
- Java JapaneseDate lengthOfYear()用法及代碼示例
- Java JapaneseDate now(Clock)用法及代碼示例
- Java JapaneseDate lengthOfMonth()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 JapaneseDate isSupported() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。