Java中的 MinguoChronology eraOf() 方法示例
Java.time.chrono.MinguoChronology类的eraOf()方法用于通过数值检索MinguoEra。
句法:
public MinguoEra eraOf(int eraValue)
参数:此方法将eraValue整数作为将为其生成MinguoEra的参数。
返回值:该方法通过数值返回民国时代。
以下是说明eraOf()方法的示例:
示例 1:
// 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
// MinguoDate Object
MinguoDate hidate
= MinguoDate.now();
// getting MinguoChronology
// used in LocalDate
MinguoChronology crono
= hidate.getChronology();
// getting MinguoEra for the
// given integer value
// by using eraOf() method
MinguoEra era = crono.eraOf(0);
// display the result
System.out.println(
"MinguoEra is: "
+ era);
}
catch (DateTimeException e) {
System.out.println(
"MinguoEra is invalid");
System.out.println(
"Exception thrown: " + e);
}
}
}
输出:
MinguoEra is: BEFORE_ROC
示例 2:
// 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
// MinguoDate Object
MinguoDate hidate
= MinguoDate.now();
// getting MinguoChronology
// used in LocalDate
MinguoChronology crono
= hidate.getChronology();
// getting MinguoEra for the
// given integer value
// by using eraOf() method
MinguoEra era = crono.eraOf(1);
// display the result
System.out.println(
"MinguoEra is: "
+ era);
}
catch (DateTimeException e) {
System.out.println(
"MinguoEra is invalid");
System.out.println(
"Exception thrown: " + e);
}
}
}
输出:
MinguoEra is: ROC
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/MinguoChronology.html#eraOf-int-