Java中的 ThaiBuddhistDate of() 方法与示例
Java.time.chrono.ThaiBuddhistDate类的of()方法用于使用传递的预测年月日,根据泰国佛教日历系统生成日期。
句法:
public static ThaiBuddhistDate of(int Year,
int month, int dayOfMonth)
参数:此方法将以下参数作为参数:
- year:year的整数值,表示 ThaiBuddhist 日期中的年份字段。
- 月:月的整数值,表示泰佛日期中的月份字段。
- day:day的整数值,表示 ThaiBuddhist 日期中的 day 字段。
返回值:该方法根据泰国佛历系统,使用传入的预知年、月、日返回日期。
异常:如果传递的参数无法形成日期,则此方法抛出DateTimeException 。
以下是说明of()方法的示例:
示例 1:
Java
// Java program to demonstrate of() 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
// ThaiBuddhistDate Object
// By using of() method
ThaiBuddhistDate hidate
= ThaiBuddhistDate.of(1444, 04, 24);
// 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);
}
}
}
Java
// Java program to demonstrate of() 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
// ThaiBuddhistDate Object
// By using of() method
ThaiBuddhistDate hidate
= ThaiBuddhistDate.of(1911, 04, -24);
// 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 1444-04-24
示例 2:
Java
// Java program to demonstrate of() 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
// ThaiBuddhistDate Object
// By using of() method
ThaiBuddhistDate hidate
= ThaiBuddhistDate.of(1911, 04, -24);
// 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);
}
}
}
输出:
Passed parameter can not form a date
Exception thrown: java.time.DateTimeException: Invalid value for DayOfMonth (valid values 1 – 28/31): -24
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistDate.html#of-int-int-int-