当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。