我正在尝试制作一个包含格里高利和伊斯兰日期的日历,我只是粗略编码的格里高利历,如同下面但我不知道如何将伊斯兰日期包括在内,任何人都可以给我一个想法如何制作这个
我想制作这样的日历 http://www.islamicfinder.org/Hcal/index.php
我的代码是:
function Calendar()
{
var now=new Date();
//---------------current date and time------------------
var day=now.getDate();
var month=now.getMonth()+1;
var year=now.getFullYear();
//-----------------------------------------------------
var FirstDay=new Date(now.getFullYear(),now.getMonth(),1);
var dayOne=FirstDay.getDay();
var LastDay=new Date(now.getFullYear(),now.getMonth()+1,0);
var dayLast=LastDay.getDay();
var noDays=getMonthDays(year,month);
var abs="<table><tr><td>sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Th</td><td>Fri</td><td>sat</td></tr><tr>";
var iterator=0;;
while(dayOne>0)
{
abs +="<td></td>"
iterator++;
dayOne--;
}
var i=1;
alert(month);
alert(year)
while(i<=noDays)
{
if(iterator>6)
{
iterator=0;
abs +="</tr><tr>"
}
abs +="<td>"+i+"</td>";
iterator++
i++;
}
var nameOfMonth=monthName(month);
document.getElementById("head").innerHTML="<h1>"+nameOfMonth+"</h1>";
document.getElementById("tble").innerHTML=abs;
}
function getMonthDays(iyear,imonth)
{
if (((iyear % 4)==0) && ((iyear % 100)!=0) || ((iyear % 400)==0))
{
var days=new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
return days[imonth];
}
else
{
var days=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
return days[imonth];
}
}
function monthName(m)
{
var months=new Array("nill","January","February","March","April","May","June","July","August","September","October","November","December");
//alert(months[m]);
return months[m];
}
答案 0 :(得分:1)
伊斯兰历法(Hijri历法)是纯粹的阴历。它包含12个月基于月球的运动,并且因为12个朔望月只有12 x 29.53 = 354.36天,所以伊斯兰历法始终比热带年份短,因此它相对于公历而变化。历法以古兰经(Sura IX,36-37)为基础,适当的遵守是穆斯林的神圣职责。
参见HERE,两个函数来改变日期(伊斯兰历史和公历)。
fromGregorian:function(/*Date*/gregorianDate){
// summary:This function returns the equivalent Islamic Date value for the Gregorian Date.
......
}
toGregorian:function(){
// summary:This returns the equevalent Grogorian date value in Islamic Date object.
......
}
查看HERE!,同时显示Gregorian和Hijri日历的日历示例。
答案 1 :(得分:0)
我终于在Gregorian到伊斯兰日期转换器的帮助下编写了日历,我的最终代码是:
function Calendar()
{
var now=new Date();
//---------------current date and time------------------
var day=now.getDate();
var month=now.getMonth()+1;
var year=now.getFullYear();
//-----------------------------------------------------
var FirstDay=new Date(now.getFullYear(),now.getMonth()+1,now.getDate());
var dayOne=FirstDay.getDay();
var LastDay=new Date(now.getFullYear(),now.getMonth()+1,0);
var dayLast=LastDay.getDay();
var noDays=getMonthDays(year,month);
var abs="<table class='cal' width='100%' cellspacing='0' cellpadding='3' border='0'><tr><td>sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Th</td><td>Fri</td><td>sat</td></tr><tr>";
var iterator=0;;
while(dayOne>0)
{
abs +="<td></td>"
iterator++;
dayOne--;
}
var i=1;
while(i<=noDays)
{
if(iterator>6)
{
iterator=0;
abs +="</tr><tr>"
}
abs +="<td>"+i+"<div class='test'> "+GregToIsl(month,i,year)+"</div>"+"</td>";
iterator++
i++;
}
var nameOfMonth=monthName(month);
document.getElementById("head").innerHTML="<h1>"+nameOfMonth+"</h1>";
document.getElementById("tble").innerHTML=abs;
}
function getMonthDays(iyear,imonth)
{
if (((iyear % 4)==0) && ((iyear % 100)!=0) || ((iyear % 400)==0))
{
var days=new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
return days[imonth];
}
else
{
var days=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
return days[imonth];
}
}
function monthName(m)
{
var months=new Array("nill","January","February","March","April","May","June","July","August","September","October","November","December");
//alert(months[m]);
return months[m];
}
function test(val)
{
return val+1;
}
function intPart(floatNum){
if (floatNum< -0.0000001){
return Math.ceil(floatNum-0.0000001)
}
return Math.floor(floatNum+0.0000001)
}
function GregToIsl(mnth,day,year)
{
d=parseInt(day)
m=parseInt(mnth)
y=parseInt(year)
delta=0
if ((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14)))
{
//added +delta=1 on jd to comply isna rulling 2007
jd=intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((367*(m-2-12*(intPart((m-14)/12))))/12)-
intPart( (3* (intPart( (y+4900+ intPart( (m-14)/12) )/100) ) ) /4)+d-32075+delta
}
else
{
//added +1 on jd to comply isna rulling
jd = 367*y-intPart((7*(y+5001+intPart((m-9)/7)))/4)+intPart((275*m)/9)+d+1729777+delta
}
//arg.JD.value=jd
//added -1 on jd1 to comply isna rulling
jd1=jd-delta
//arg.wd.value=weekDay(jd1%7)
l=jd-1948440+10632
n=intPart((l-1)/10631)
l=l-10631*n+354
j=(intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238))
l=l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29
m=intPart((24*l)/709)
d=l-intPart((709*m)/24)
y=30*n+j-30
return d+"-"+m;
}
这可能不是优化方法,但这是有效的