LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

# Pure JavaScript Formula To Calculate And Show Islamic Hijri Dates

If you do not need fancy looking Hijri calendar widget, or you want to style the calendar text by yourself, or you are a webmaster or a web developer that want to build your own Hijri calendar web applications, then the following code may be of use.

The script (modified from Robert van Gent’s page) calculates approximate Hijri dates from the current computer’s date. It is based on an arithmetical calculation to match the current moon phase. The calculation is based on a 30-year lunar cycle where the length of the lunar months is defined alternatingly as 29 or 30 days. Every two or three years an extra day is added at the end of the year to keep up with the phase of the moon. This formula is also similar to the “Kuwaiti Algorithm” used by Microsoft to define Hijri Calendar dates.

There are many code snippets available online or on many other blogs and websites but everyone is not able to optimize your blog or website so you need some optimized code snippet. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready to use code and paste it where you want.

## Features:

1. Light Weight.
2. Pure Vanilla JavaScript.
3. Cross Browser.
4. No External Files.
5. Fully Customizable.
6. Set Opacity On After Detecting.

## How To Detect Browser Using Pure Vanilla JavaScript?

There are a few easy and understandable steps to achieve your desired functionality using pure Vanilla JavaScript that we are gonna share below. Follow each step perfectly.

### JavaScript:

```<script>
function gmod(n, m) {
return ((n % m) + m) % m;
}

var today = new Date();
today = new Date(todaymili);
}
day = today.getDate();
month = today.getMonth();
year = today.getFullYear();
m = month + 1;
y = year;
if (m < 3) {
y -= 1;
m += 12;
}
a = Math.floor(y / 100.);
b = 2 - a + Math.floor(a / 4.);
if (y < 1583) b = 0;
if (y == 1582) {
if (m > 10) b = -10;
if (m == 10) {
b = 0;
if (day > 4) b = -10;
}
}
jd = Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + day + b - 1524;
b = 0;
if (jd > 2299160) {
a = Math.floor((jd - 1867216.25) / 36524.25);
b = 1 + a - Math.floor(a / 4.);
}
bb = jd + b + 1524;
cc = Math.floor((bb - 122.1) / 365.25);
dd = Math.floor(365.25 * cc);
ee = Math.floor((bb - dd) / 30.6001);
day = (bb - dd) - Math.floor(30.6001 * ee);
month = ee - 1;
if (ee > 13) {
cc += 1;
month = ee - 13;
}
year = cc - 4716;
wd = gmod(jd + 1 - adjust, 7) + 1;
} else {
wd = gmod(jd + 1, 7) + 1;
}
iyear = 10631. / 30.;
epochastro = 1948084;
epochcivil = 1948085;
shift1 = 8.01 / 60.;
z = jd - epochastro;
cyc = Math.floor(z / 10631.);
z = z - 10631 * cyc;
j = Math.floor((z - shift1) / iyear);
iy = 30 * cyc + j;
z = z - Math.floor(j * iyear + shift1);
im = Math.floor((z + 28.5001) / 29.5);
if (im == 13) im = 12;
id = z - Math.floor(29.5001 * im - 29);
var myRes = new Array(8);
myRes[0] = day;
//calculated day (CE)
myRes[1] = month-1;
//calculated month (CE)
myRes[2] = year;
//calculated year (CE)
myRes[3] = jd-1;
//julian day number
myRes[4] = wd-1;
//weekday number
myRes[5] = id;
//islamic date
myRes[6] = im-1;
//islamic month
myRes[7] = iy;
//islamic year
return myRes;
}
function writeIslamicDate(adjustment) { var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt"); var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir", "Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban", "Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja"); var iDate = kuwaiticalendar(adjustment); var outputIslamicDate = wdNames[iDate[4]] + ", " + iDate[5] + " " + iMonthNames[iDate[6]] + " " + iDate[7] + " AH"; return outputIslamicDate; }
</script>```

### Example Outputs:

Below is an example output of the above script (the writeIslamicDate function) without date adjustment:

Khams, 10 Jumadal Akhira 1443 AH

## Customization:

Use the below code to call the function. You can make it in the loop to update the time minutes by minutes.

`document.write(writeIslamicDate());`

Recommended For You:
Secure Your Web Pages To Be Embedded Via HTML FRAMES

Khams, 11 Jumadal Akhira 1443 AH

The code:

`document.write(writeIslamicDate(1));`

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

## Troubleshooting the Errors:

Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.