Java中的 ThaiBuddhistChronology dateNow(ZoneId) 方法与示例
使用Java.time.chrono.ThaiBuddhistChronology类的dateNow()方法,从指定时区的系统时钟中,根据ThaiBuddhist 日历系统获取当前ThaiBuddhist。
句法:
public ThaiBuddhistDate dateNow(ZoneId zone)
参数:该方法以zone id的对象为参数。
返回值:该方法从指定的时钟对象中返回按照泰国佛教日历系统的泰国佛教日期。
以下是说明dateNow()方法的示例:
示例 1:
// Java program to demonstrate
// dateNow() 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();
// creating and initializing ZoneId object
ZoneId id = ZoneId.systemDefault();
// getting ThaiBuddhistDate for the
// given zoneid object
// by using dateNow() method
ThaiBuddhistDate date = crono.dateNow(id);
// display the result
System.out.println("ThaiBuddhistDate is: "
+ date);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出:
ThaiBuddhistDate is: ThaiBuddhist BE 2563-04-19
示例 2:
// Java program to demonstrate
// dateNow() 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();
// creating and initializing ZoneId object
ZoneId id = ZoneId.of("Europe/Paris");
// getting ThaiBuddhistDate for the
// given zoneid object
// by using dateNow() method
ThaiBuddhistDate date = crono.dateNow(id);
// display the result
System.out.println("ThaiBuddhistDate is: "
+ date);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出:
ThaiBuddhistDate is: ThaiBuddhist BE 2563-04-19
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistChronology.html#dateNow-java.time.ZoneId-