Mahmoud Elshamy
Mahmoud Elshamy

Reputation: 598

How to convert Hijri (Islamic) date to Gregorian date

I want to convert Hijri date to Gregorian date! I've searched, but unfortunately I found a java class for converting Gregorian to Hijri. I need the opposite.

HijriCalendar.java: https://gist.github.com/fatfingers/6492017

Upvotes: 2

Views: 7486

Answers (4)

Parniyan
Parniyan

Reputation: 339

Try this:

Kotlin:

import java.time.LocalDate
import java.time.chrono.HijrahChronology
import java.time.chrono.HijrahDate

@RequiresApi(Build.VERSION_CODES.O)
fun convertHijriToGregorian(hijriYear: Int, hijriMonth: Int, hijriDay: Int): LocalDate {
    val hijriDate = HijrahDate.of(hijriYear, hijriMonth, hijriDay)
    return LocalDate.from(hijriDate)
}

And use it like this:

@RequiresApi(Build.VERSION_CODES.O)
fun main() {
    val hijriYear = 1443
    val hijriMonth = 8
    val hijriDay = 5

    val gregorianDate = convertHijriToGregorian(hijriYear, hijriMonth, hijriDay)
    println("Gregorian date: $gregorianDate")
}

Java:

import java.time.LocalDate;
import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;

public class Main {
    public static void main(String[] args) {
        int hijriYear = 1443;
        int hijriMonth = 8;
        int hijriDay = 5;

        LocalDate gregorianDate = convertHijriToGregorian(hijriYear, hijriMonth, hijriDay);
        System.out.println("Gregorian date: " + gregorianDate);
    }

    public static LocalDate convertHijriToGregorian(int hijriYear, int hijriMonth, int hijriDay) {
        HijrahDate hijriDate = HijrahDate.of(HijrahChronology.INSTANCE, hijriYear, hijriMonth, hijriDay);
        return LocalDate.from(hijriDate);
    }
}

Upvotes: 1

Ibrahim AlDosary
Ibrahim AlDosary

Reputation: 1

General Method for Converting Hijri Dates to Gregorian dates

The problem: I have a long list of Hijri dates I wanted to convert to a list of Gregorian dates. Solution: Here are the steps, I used to convert my list:

  1. I Copied my Hijri list into MS Word as a table.
  2. I Converted the table into a text, then to a table with 3 columns (date, month, year). The purpose of this was to allow for manipulating numbers when converting into days. Then I copied this table into an Excel sheet with Day, Month, Year columns as A2, B2, C2 columns, respectably.
  3. I selected a Hijri date as a reference date for conversion. The date was 1/1/1432, since the first date on my list is 10/10/1432. (you can arbitrarily select any Hijri date to be your reference date).
  4. I converted the reference date (1/1/1432) into a reference Gregorian date using online Hijri to Gregorian conversion sites. It was 7/12/2010.
  5. I calculated the difference in days between my Hijri reference date, and the dates on my list using the following formula: =A2+(B2-1)*29.53059+(C2-1432)*354.3671, where A2=Day, B2=Month, C2=Year, 1432 is the reference year, and the other two constants in the equation; 29.53059, 354.3671 are the average length in days for Hijri month and year respectively.
  6. Now I a have a list for the difference in days between each date on my list and my Hijri reference date. For example, the number of days for my first Hijri date was: 275.77531
  7. To get all Gregorian dates corresponding to every Hijri date all I had to do was to add the difference in days to my Gregorian reference date (1/12/2010). In fact, you can get any Gregorian date corresponding to any Hijri date using this sheet, provided the dates are not before 1/1/1900, which is the limiting date in Excel.
    I checked random dates conversions calculated from my sheet and the conversion from web programs and found the results to be almost perfect (plus or minus on day). I was assured when it gave the exact day of Eid Al-fitr for this year (1/10/1445) as 10/4/2024.
    My sheet can be accessed at: https://1drv.ms/x/s!ArEGLFnTDdDChKQFndbmx2gTYXIfPw?e=uZ4FZe

Upvotes: 0

Stephen
Stephen

Reputation: 11

The formula to convert Muslim (M) dates to CE is:

CE = ((M x 970224)/1000000)+ 621.5774 = CE.nnn

then 0.nnn x 365 = day of the CE year M year began.

From that you can determine the day you are looking for from the Muslim month chart:

  1. Muharram = 30 days;
  2. Safar = 29 days;
  3. Rabia 1 = 30 days;
  4. Rabia 2 = 29 days;
  5. Jumada 1 = 30 days;
  6. Jumada 2 = 29 days;
  7. Rajab = 3 days;
  8. Shaban = 29 days;
  9. Ramadan = 30 days;
  10. Shawwal = 29 days;
  11. Zu'lKadah = 30 days;
  12. Zu'lhijjah = 29 days (30 days if leap year).

Years run in 30 year cycles.

Each cycle starts on 15 June. The 2nd, 5th, 7th, 10th, 13th, 16th, 18th, 21st, 24th 26th and 29th are leap years.

One cycle = 10, 631 days.

Hope this helps. I also have the formula for converting CE dates to Muslim dates.

Upvotes: 1

john
john

Reputation: 613

You can use Joda-Time for this.

If you create an Islamic cronology and call withUTC() it should return an UTC cronology which can be converted to whatever is needed.

However, according to this post, the joda-Time implementation is only an approximation.

Upvotes: 3

Related Questions