Java中的 ThaiBuddhistDate now(Clock) 方法与示例
Java.time.chrono.ThaiBuddhistDate类的now()方法用于从指定的时钟根据泰国佛教日历系统获取当前的泰国佛教日期。
句法:
public static ThaiBuddhistDate
now(Clock clock)
参数:此方法获取时钟对象,该对象将根据该对象形成 ThaiBuddhist 日期。
返回值:该方法从指定的时钟根据泰国佛教日历系统返回当前的泰国佛教日期。
下面是说明now()方法的示例:
示例 1:
// Java program to demonstrate now() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing clock
Clock clock
= Clock.systemUTC();
// Creating and initializing
// ThaiBuddhistDate Object
ThaiBuddhistDate hidate
= ThaiBuddhistDate.now(clock);
// Display the result
System.out.println(
"ThaiBuddhistDate: "
+ hidate);
}
catch (DateTimeException e) {
System.out.println(
"Passed parameter can"
+ " not form a date");
System.out.println(
"Exception thrown: "
+ e);
}
}
}
输出:
ThaiBuddhistDate: ThaiBuddhist BE 2563-05-03
示例 2:
// Java program to demonstrate now() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing clock
Clock clock
= Clock.systemDefaultZone();
// Creating and initializing
// ThaiBuddhistDate Object
ThaiBuddhistDate hidate
= ThaiBuddhistDate.now(clock);
// Display the result
System.out.println(
"ThaiBuddhistDate: "
+ hidate);
}
catch (DateTimeException e) {
System.out.println(
"Passed parameter can"
+ " not form a date");
System.out.println(
"Exception thrown: "
+ e);
}
}
}
输出:
ThaiBuddhistDate: ThaiBuddhist BE 2563-05-03
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistDate.html#now-java.time.Clock-