Java中的 IsoChronology dateEpochDay() 方法与示例
Java.time.chrono.IsoChronology类的dateEpochDay()方法用于根据 ISO 系统从大纪元获取本地日期。
句法:
public IsoDate dateEpochDay(long epochDay)
参数:该方法以long类型的epochDay作为参数。
返回值:此方法根据 Hijrah 日历系统从另一个 TemporalAccessor 对象返回IsoDate 。
以下是说明dateEpochDay()方法的示例:
示例 1:
Java
// Java program to demonstrate
// dateEpochDay() 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 LocalDate Object
LocalDate hidate = LocalDate.now();
// getting IsoChronology used in LocalDate
IsoChronology crono = hidate.getChronology();
// display the result
System.out.println("current LocalDate is: "
+ hidate);
// getting LocalDate for the
// given TemporalAccessor object
// by using date() method
hidate = crono.dateEpochDay(23456);
// display the result
System.out.println("\nLocalDate(according "
+ "to ephochday) is: "
+ hidate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
Java
// Java program to demonstrate
// dateEpochDay() 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 LocalDate Object
LocalDate hidate = LocalDate.of(00000, 01, 01);
// getting IsoChronology used in LocalDate
IsoChronology crono = hidate.getChronology();
// display the result
System.out.println("current LocalDate is: "
+ hidate);
// getting LocalDate for the
// given TemporalAccessor object
// by using date() method
hidate = crono.dateEpochDay(-999999999);
// display the result
System.out.println("\nLocalDate(according "
+ "to ephochday) is: "
+ hidate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出
current LocalDate is: 2021-06-25
LocalDate(according to ephochday) is: 2034-03-22
示例 2:
Java
// Java program to demonstrate
// dateEpochDay() 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 LocalDate Object
LocalDate hidate = LocalDate.of(00000, 01, 01);
// getting IsoChronology used in LocalDate
IsoChronology crono = hidate.getChronology();
// display the result
System.out.println("current LocalDate is: "
+ hidate);
// getting LocalDate for the
// given TemporalAccessor object
// by using date() method
hidate = crono.dateEpochDay(-999999999);
// display the result
System.out.println("\nLocalDate(according "
+ "to ephochday) is: "
+ hidate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出
current LocalDate is: 0000-01-01
LocalDate(according to ephochday) is: -2735938-12-30
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/IsoChronology.html#dateEpochDay-long-