📌  相关文章
📜  Java中的 JapaneseDate isSupported() 方法与示例

📅  最后修改于: 2022-05-13 01:55:40.807000             🧑  作者: Mango

Java中的 JapaneseDate isSupported() 方法与示例

Java.time.chrono.JapaneseDate类的isSupported()方法用于检查是否支持特定的 chrono 字段。

句法:

public boolean isSupported(TemporalField field)

参数:此方法接受 Chrono 字段的类型,以检查它是否与该特定日期兼容。

返回值:如果此日期与传递的字段兼容,则此方法返回布尔值,否则返回 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-