📜  带有示例的Java中的 HijrahDate of(int, int, int) 方法

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

带有示例的Java中的 HijrahDate of(int, int, int) 方法

Java.time.chrono.HijrahDate类的of()方法用于根据伊斯兰教回历系统使用传递的预测年、月和日期生成日期。

句法:

public static HijrahDate of(int Year,
            int month, int dayOfMonth)

参数:此方法将以下参数作为参数:

  • 年份:表示回历日期中年份字段的年份整数值。
  • 月份:月份的整数值,表示回历日期中的月份字段。
  • 日:这是表示回历日期中的日字段的日的整数值。

返回值:此方法根据回历系统,使用传入的预知年、月、日返回日期

异常:如果传递的参数无法形成日期,则此方法抛出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
            // HijrahDate Object
            // By using of() method
            HijrahDate hidate
                = HijrahDate.of(1444, 04, 24);
  
            // 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 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
            // HijrahDate Object
            // By using of() method
            HijrahDate hidate
                = HijrahDate.of(2014, 04, 24);
  
            // 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 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
            // HijrahDate Object
            // By using of() method
            HijrahDate hidate
                = HijrahDate.of(2014, 04, 24);
  
            // 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);
        }
    }
}
输出:
passed parameter can not form a date
Exception thrown: java.time.DateTimeException:
                  Invalid Hijrah date,
                  year: 2014, month: 4

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahDate.html#of-int-int-int-