Islamic Date (Hijiri)

2k views Asked by At

Does anybody know of a way to display the current date using the Islamic (Hajiri) date? Preferrably in PHP and/or Javascript.

Specifically in this format? "10 Safar, 1442"

I have been looking and looking and looking. I can find others using it, and when I search for "display Hajiri date", I get a bunch of sites about Muslim dating... not what I'm looking for, obviously.

I don't need anything special, just the date according to the location of the visitor to a site.

3

There are 3 answers

1
Mark Reed On BEST ANSWER

There is a Hijri Javascript library for Moment.js (https://ej2.syncfusion.com/documentation/calendar/islamic-calendar/); a quick Google for 'hijri calendar php' turns up a number of libraries for that language as well.

If you're interested in understanding how they work, perhaps implementing your own solution, I recommend the book Calendrical Calculations by Reingold and Dershowitz, which has a chapter on the Islamic calendar, and includes formulas that can be used to approximate it. That includes an attempt at observational accuracy that uses some relatively complex astronomical equations to compute the time of the lunar conjunction with a high degree of precision for dates around the present. The book comes with source code too, albeit in Lisp (the book grew out of the original implementation of the Hebrew calendar for Emacs by one of the authors).

4
Shakeel On

You must check this library. They claim "A Python package to convert accurately between Hijri and Gregorian dates using the Umm al-Qura calendar of Saudi Arabia."

>> from hijri_converter import convert
>>> hijri = convert.Gregorian(1982, 12, 2).to_hijri() 
>>> hijri.datetuple() 
(1403, 2, 17) 
>>> hijri.dmyformat()
 '17/02/1403'
 >>> hijri.month_name()
 'Safar' 
>>> hijri.day_name() 
'Thursday' 
>>> hijri.notation() 
'AH'
0
Mohsen Alyafei On

Here is one way to display the Hijri Date in the format requested given a Gregorian Date.

function myHijriDateFormat(date) {
let startDate= new Date(date),
    c= 'en-u-ca-islamic-umalqura-nu-latn',  // use 'islamic-umalqura' calendar for the islamic date
    n='numeric',
    iDay  =new Intl.DateTimeFormat(c,{day  :n}).format(startDate),
    iMonth=new Intl.DateTimeFormat(c,{month:'long'}).format(startDate),
    iYear =new Intl.DateTimeFormat(c,{year :n}).format(startDate).split(" ")[0];

    return iDay+" "+iMonth+", "+iYear;
}
    console.log(myHijriDateFormat(new Date(Date.now()))); // today's date
    console.log(myHijriDateFormat("2022-04-02"));         // first Ramadan 2022