📌  相关文章
📜  带有示例的Java中的 HijrahChronology eraOf() 方法

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

带有示例的Java中的 HijrahChronology eraOf() 方法

Java.time.chrono.HijrahChronology类的eraOf()方法用于通过使用数值 1 检索 Hijrah Era,因为 HijrahChronology 仅包含一个 HijrahEra。

句法:

public HijrahEra eraOf(int eraValue)

参数:此方法将eraValue整数作为要为其生成 HijrahEra 的参数。

返回值:此方法使用数值 1 返回Hijrah Era ,因为 HijrahChronology 仅包含一个 HijrahEra 。

以下是说明eraOf()方法的示例:

示例 1:

Java
// Java program to demonstrate
// eraOf() method
 
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // HijrahDate Object
            HijrahDate hidate = HijrahDate.now();
 
            // getting HijrahChronology
            // used in HijrahDate
            HijrahChronology crono
                = hidate.getChronology();
 
            // getting HijrahEra for the
            // given integer value
            // by using eraOf() method
            HijrahEra era = crono.eraOf(1);
 
            // display the result
            System.out.println("HijrahEra is: "
                               + era);
        }
        catch (DateTimeException e) {
            System.out.println("HijrahEra is invalid");
            System.out.println("Exception thrown: " + e);
        }
    }
}


Java
// Java program to demonstrate
// eraOf() method
 
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // HijrahDate Object
            HijrahDate hidate = HijrahDate.now();
 
            // getting HijrahChronology
            // used in HijrahDate
            HijrahChronology crono
                = hidate.getChronology();
 
            // getting HijrahEra for the
            // given integer value
            // by using eraOf() method
            HijrahEra era = crono.eraOf(0);
 
            // display the result
            System.out.println("HijrahEra is: "
                               + era);
        }
        catch (DateTimeException e) {
            System.out.println("HijrahEra is invalid");
            System.out.println("Exception thrown: " + e);
        }
    }
}


输出:
HijrahEra is: AH

示例 2:

Java

// Java program to demonstrate
// eraOf() method
 
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // HijrahDate Object
            HijrahDate hidate = HijrahDate.now();
 
            // getting HijrahChronology
            // used in HijrahDate
            HijrahChronology crono
                = hidate.getChronology();
 
            // getting HijrahEra for the
            // given integer value
            // by using eraOf() method
            HijrahEra era = crono.eraOf(0);
 
            // display the result
            System.out.println("HijrahEra is: "
                               + era);
        }
        catch (DateTimeException e) {
            System.out.println("HijrahEra is invalid");
            System.out.println("Exception thrown: " + e);
        }
    }
}
输出:
HijrahEra is invalid
Exception thrown: java.time.DateTimeException: invalid Hijrah era

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahChronology.html#eraOf-int-