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

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

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

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

句法:

public static JapaneseDate now(ZoneId zone)

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

返回值:该方法根据日本日历系统从指定时钟返回当前日本日期

下面是说明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
            // JapaneseDate Object
            JapaneseDate hidate
                = JapaneseDate.now(id);
  
            // Display the result
            System.out.println("JapaneseDate: "
                               + 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
            // JapaneseDate Object
            JapaneseDate hidate
                = JapaneseDate.now(id);
  
            // Display the result
            System.out.println("JapaneseDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}


输出:
JapaneseDate: Japanese Heisei 32-03-23

示例 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
            // JapaneseDate Object
            JapaneseDate hidate
                = JapaneseDate.now(id);
  
            // Display the result
            System.out.println("JapaneseDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}
输出:
JapaneseDate: Japanese Heisei 32-03-23

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