 Calculate Islamic Calendar using javascript. Islamic countries are still using, together with the gregorian calendar a strictly lunar calendar; years are numbered starting with the Egira (622 July 16: Mohammed leaves Mecca for Medina). This perpetual calendar works for every date after the Egira.

The Koran states that new month should begin immediately after New Moon, or better at the first sighting of the growing moon. This exact moment is almost impossible to predict; for simplicity islamic perpetual calendar use the following rule, which works rather good: the year has twelve month alternatively of 30 and 29 days; the common year has then 354 days; since the lunar month is 44m longer than 29,5 days a 30th day is added to the last month. This applies on 11 years out of 30 according to the sequence: 2,5,7,10,13,16,18,21,24,26,29. These years have so 355 years.

With such a rule 30 years have exactly 10631 days, while 360 moons make 10631.0125 days; there is still a little mistake (1/80 of a day) but you need 2400 years to have a whole day error.

[code lang="js"]

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;

} 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 = day; //calculated day (CE)
myRes = month-1; //calculated month (CE)
myRes = year; //calculated year (CE)
myRes = jd-1; //julian day number
myRes = wd-1; //weekday number
myRes = id; //islamic date
myRes = im-1; //islamic month
myRes = iy; //islamic year

return myRes;
}
var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
Javascript Calculate Islamic Calendar Reviewed by Admin on 6:22 AM Rating: 5