📌  相关文章
📜  带有示例的Java中的 HijrahDate now(Clock) 方法

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

带有示例的Java中的 HijrahDate now(Clock) 方法

Java.time.chrono.HijrahDate类的now()方法用于根据回历系统从指定时钟获取当前回历日期。

句法:

public static HijrahDate now(Clock clock)

参数:此方法采用时钟对象,在此基础上将形成 Hijrah 日期。

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

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


输出:
HijrahDate: Hijrah-umalqura AH 1441-06-25

示例 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 clock
            Clock clock
                = Clock.systemDefaultZone();
  
            // Creating and initializing
            // HijrahDate Object
            HijrahDate hidate
                = HijrahDate.now(clock);
  
            // Display the result
            System.out.println("HijrahDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}
输出:
HijrahDate: Hijrah-umalqura AH 1441-06-25

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