Java中的 JapaneseChronology eras() 方法与示例
Java.time.chrono.JapaneseChronology类的 eras ()方法用于检索该特定日本年表下的所有时代。
句法:
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
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now();
// getting JapaneseChronology
// used in JapaneseDate
JapaneseChronology crono
= hidate.getChronology();
// getting all JapaneseEras present
// by using eraOf() method
List list = crono.eras();
// display the result
System.out.println(
"JapaneseEra is: "
+ (list.iterator()).next());
}
catch (DateTimeException e) {
System.out.println(
"JapaneseEra is invalid");
System.out.println(
"Exception thrown: " + e);
}
}
}
输出:
JapaneseEra is: Meiji
示例 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
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now();
// getting JapaneseChronology
// used in JapaneseDate
JapaneseChronology crono
= hidate.getChronology();
// getting all JapaneseEras present
// by using eraOf() method
List list = crono.eras();
// getting list Iterator
Iterator iter = list.iterator();
// display the result
System.out.println("List of IsoEra : ");
for (int i = 0; i < 4; i++)
System.out.println(iter.next());
}
catch (DateTimeException e) {
System.out.println(
"JapaneseEra is invalid");
System.out.println(
"Exception thrown: " + e);
}
}
}
输出:
List of IsoEra :
Meiji
Taisho
Showa
Heisei
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/JapaneseChronology.html#eras–