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

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

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

Java.time.chrono.HijrahChronology类的 eras ()方法用于检索此特定 hijrah 年表下的所有时代。

句法:

public List eras()

参数:此方法不接受任何参数作为参数。

返回值:此方法返回此特定回历年表下的所有时代。

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

示例 1:

// Java program to demonstrate
// eras() 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 all HijrahEras present
            // by using eraOf() method
            List list = crono.eras();
  
            // display the result
            System.out.println("HijrahEra is: "
                               + (list.iterator()).next());
        }
        catch (DateTimeException e) {
            System.out.println("HijrahEra is invalid");
            System.out.println("Exception thrown: " + e);
        }
    }
}
输出:
HijrahEra is: AH

示例 2:

// Java program to demonstrate
// eras() 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(
                    Clock.systemDefaultZone());
  
            // getting HijrahChronology
            // used in HijrahDate
            HijrahChronology crono
                = hidate.getChronology();
  
            // getting all HijrahEras present
            // by using eraOf() method
            List list = crono.eras();
  
            // display the result
            System.out.println("HijrahEra is: "
                               + (list.iterator())
                                     .next());
        }
        catch (DateTimeException e) {
            System.out.println("HijrahEra is invalid");
            System.out.println("Exception thrown: " + e);
        }
    }
}
输出:
HijrahEra is: AH

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahChronology.html#eras–