📌  相关文章
📜  Java中的 ThaiBuddhistDate from() 方法和示例

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

Java中的 ThaiBuddhistDate from() 方法和示例

Java.time.chrono.ThaiBuddhistDate类的from()方法用于根据特定时间对象的 ThaiBuddhist 日历系统获取 ThaiBuddhist 日期。

句法:

public static ThaiBuddhistDate
      from(TemporalAccessor temporal)

参数:此方法获取任何时间访问器的对象,该对象将基于哪个 ThaiBuddhist 日期将被形成。

返回值:该方法根据泰国佛教日历系统返回指定时间对象的泰国佛教日期。

以下是说明from()方法的示例:

示例 1:

// Java program to demonstrate from() 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
            // TemporalAccessor object
            ZonedDateTime
                zonedate
                = ZonedDateTime.parse(
                    "2018-10-25T23:12:31."
                    + "123+02:00[Europe/Paris]");
  
            // Creating and initializing
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate
                      .from(zonedate);
  
            // 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 2561-10-25

示例 2:

// Java program to demonstrate from() 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
            // TemporalAccessor object
            LocalDateTime
                localdate
                = LocalDateTime.parse(
                    "2018-12-30T19:34:50.63");
  
            // Creating and initializing
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate
                      .from(localdate);
  
            // 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 2561-12-30

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistDate.html#from-java.time.temporal.TemporalAccessor-