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

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

Java中的 ThaiBuddhistDate now(ZoneId) 方法和示例

Java.time.chrono.ThaiBuddhistDate类的now()方法用于根据指定区域的泰国佛教日历系统获取当前的泰国佛教日期。

句法:

public static ThaiBuddhistDate
              now(ZoneId zone)

参数:此方法获取区域id的对象,根据该对象将形成ThaiBuddhist 日期。

返回值:该方法从指定的时钟根据泰国佛教日历系统返回当前的泰国佛教日期

下面是说明now()方法的示例:

示例 1:

Java
// 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 ZoneId
            ZoneId id
                = ZoneId.systemDefault();
  
            // Creating and initializing
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now(id);
  
            // 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 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 ZoneId
            ZoneId id
                = ZoneId.of("Z");
  
            // Creating and initializing
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now(id);
  
            // 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-08

示例 2:

Java

// 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 ZoneId
            ZoneId id
                = ZoneId.of("Z");
  
            // Creating and initializing
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now(id);
  
            // 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-08

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