📌  相关文章
📜  Java中的 ThaiBuddhistChronology dateEpochDay() 方法与示例

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

Java中的 ThaiBuddhistChronology dateEpochDay() 方法与示例

Java.time.chrono.ThaiBuddhistChronology类的dateEpochDay()方法用于根据 ThaiBuddhist 日历系统从大纪元获取当地日期。
句法:

public ThaiBuddhistDate dateEpochDay(long epochDay)

参数:该方法以long类型的epochDay作为参数。
返回值:该方法从大纪元开始根据泰国佛教日历系统返回当地日期。
异常:如果给定的纪元日无法形成结构化日期,则此方法抛出DateTimeException
以下是说明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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // getting ThaiBuddhistChronology
            // used in ThaiBuddhistDate
            ThaiBuddhistChronology crono
                = hidate.getChronology();
 
            // display the result
            System.out.println("current ThaiBuddhistDate is: "
                               + hidate);
 
            // getting ThaiBuddhistDate for the
            // given TemporalAccessor object
            // by using date() method
            hidate = crono.dateEpochDay(23456);
 
            // display the result
            System.out.println("\nThaiBuddhistDate(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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // getting ThaiBuddhistChronology
            // used in ThaiBuddhistDate
            ThaiBuddhistChronology crono
                = hidate.getChronology();
 
            // display the result
            System.out.println("current ThaiBuddhistDate is: "
                               + hidate);
 
            // getting ThaiBuddhistDate for the
            // given TemporalAccessor object
            // by using date() method
            hidate = crono.dateEpochDay(-99999999);
 
            // display the result
            System.out.println("\nThaiBuddhistDate(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 ThaiBuddhistDate is: ThaiBuddhist BE 2564-06-25

ThaiBuddhistDate(according to ephochday) is: ThaiBuddhist BE 2577-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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // getting ThaiBuddhistChronology
            // used in ThaiBuddhistDate
            ThaiBuddhistChronology crono
                = hidate.getChronology();
 
            // display the result
            System.out.println("current ThaiBuddhistDate is: "
                               + hidate);
 
            // getting ThaiBuddhistDate for the
            // given TemporalAccessor object
            // by using date() method
            hidate = crono.dateEpochDay(-99999999);
 
            // display the result
            System.out.println("\nThaiBuddhistDate(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 ThaiBuddhistDate is: ThaiBuddhist BE 2564-06-25

ThaiBuddhistDate(according to ephochday) is: ThaiBuddhist BEFORE_BE 271279-04-21

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistChronology.html#dateEpochDay-long-