Open In App

HijrahDate of(int, int, int) method in Java with Example

Last Updated : 27 Feb, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The of() method of java.time.chrono.HijrahDate class is used to generate the date according to Islamic hijri calendar system by using the passed proleptic year, month and date.

Syntax:

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

Parameter: This method takes the following argument as a parameter:

  • year: which is the integer value of year which represent the year field in hijrah date.
  • month: which is the integer value of month which represent the month field in hijrah date.
  • day: which is the integer value of day which represent the day field in hijrah date.

Return Value: This method returns the date according to Islamic Hijri calendar system by using the passed proleptic year, month and date.

Exception: This method throws DateTimeException if the passed parameter is unable to form date.

Below are the examples to illustrate the of() method:

Example 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);
        }
    }
}


Output:

HijrahDate: Hijrah-umalqura AH 1444-04-24

Example 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);
        }
    }
}


Output:

passed parameter can not form a date
Exception thrown: java.time.DateTimeException:
                  Invalid Hijrah date,
                  year: 2014, month: 4

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/HijrahDate.html#of-int-int-int-



Similar Reads

TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
The getOffset(int era, int yr, int mon, int day, int dayOfWeek, int millisec) method of TimeZone class in Java is used to know the offset value of this TimeZone at a specific date or modified date in case of daylight savings, from the UTC or the Universal Time Coordinated. This offset value can be added to get the local time. Syntax: public abstrac
2 min read
HijrahDate atTime() method in Java with Example
The atTime() method of java.time.chrono.HijrahDate class is used to add up this HijrahDate time with a local time for producing an equivalent date and time .Syntax: public final ChronoLocalDateTime atTime(LocalTime localTime)Parameter: This method takes the object of type LocalTime as a parameter.Return Value: This method returns the Chrono local d
2 min read
HijrahDate equals() method in Java with Example
The equals() method of java.time.chrono.HijrahDate class is used to compare this hijrah date with another hijrah date.Syntax: public boolean equals(Object obj) Parameter: This method takes an equivalent object as a parameter to compare with this hijrahdate .Return Value: This method returns true if both the dates are equal otherwise false.Below are
2 min read
HijrahDate getChronology() method in Java with Example
The getChronology() method of java.time.chrono.HijrahDate class is used to retrieve the chronology of this hijrah date under which this date lies.Syntax: public HijrahChronology getChronology()Parameter: This method does not accept any parameter.Return Value: This method returns the chronology of this hijrah date.Below are the examples to illustrat
2 min read
HijrahDate getEra() method in Java with Example
The getEra() method of java.time.chrono.HijrahDate class is used to retrieve the era related to this hijrah date.Syntax: public HijrahEra getEra() Parameter: This method does not accept any parameter.Return Value: This method returns the era of this hijrah date. Below are the examples to illustrate the getEra() method:Example 1: Java Code // Java p
2 min read
HijrahDate getLong() method in Java with Example
The getLong() method of java.time.chrono.HijrahDate class is used to retrieve the passed temporal field in long format. Syntax: public long getLong(TemporalField field) Parameter: This method takes any type of temporal field as a parameter. Return Value: This method returns the passed temporal field in long format. Below are the examples to illustr
2 min read
HijrahDate hashCode() method in Java with Example
The hashCode() method of java.time.chrono.HijrahDate class is used to get the hash code for the particular hijrah date. Syntax: public int hashCode() Parameter: This method does not accept any argument as a parameter. Return Value: This method returns the hash code for the particular hijrah date. Below are the examples to illustrate the hashCode()
2 min read
HijrahDate toString() method in Java with Example
The toString() method of java.time.chrono.HijrahDate class is used to represent the hijrah date into the string format.Syntax: public String toString() Parameter: This method does not accept any argument as a parameter.Return Value: This method returns the hijrah date into the string format.Below are the examples to illustrate the toString() method
2 min read
HijrahDate toEpochDay() method in Java with Example
The toEpochDay() method of java.time.chrono.HijrahDate class is used to get the number of epoch days present in between the current hijrah date and 1389-10-22. Syntax: public long toEpochDay() Parameter: This method does not accept any argument as a parameter. Return Value: This method returns the number of epoch days present in between the current
2 min read
HijrahDate range() method in Java with Example
The range() method of java.time.chrono.HijrahDate class is used get the range from the specified field of type TemporalField. Syntax: public ValueRange range(TemporalField field) Parameter: This method takes the field of type TemporalField as a parameter whose range is to be obtained. Return Value: This method returns range of the specified field i
2 min read