2013-10-19 61 views
1

我想製作一個包含陽曆和伊斯蘭日期的日曆,我只是粗略編碼的陽曆,但是我不知道如何包含伊斯蘭日期這一點,可以在任何一個,請給我的想法是如何使這個如何製作陽曆和伊斯蘭日曆中的一個(javascript)

我要讓日曆這樣 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]; 
} 

回答

1

伊斯蘭教歷(回曆)是一個純粹的陰曆。它包含基於月球運動的12個月,並且因爲12個朔望月只有12×29.53 = 354.36天,伊斯蘭日曆一直比熱帶年短,因此它相對於公曆日曆變化。曆法基於古蘭經(古蘭經九,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!,日曆的例子,可以顯示在同一時間都公曆和回曆。

0

我終於編碼萬年曆在...的幫助下陽曆伊斯蘭日期轉換我最後的代碼是:

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; 


} 

這可能不是最優化的方法,但是這是工作

相關問題