當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java JapaneseDate isSupported()用法及代碼示例


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

參考: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/JapaneseDate.html#isSupported-java.time.temporal.TemporalField-




相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 JapaneseDate isSupported() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。