嗨我需要在javascript中将Hgorridate的格里高利日期代码 [英] Hi i need the code for Gregorian date to Hijridate in javascript
本文介绍了嗨我需要在javascript中将Hgorridate的格里高利日期代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我在服务器端获得了Gregorian日期到Hijridate的代码但是为了更好的性能我需要它在客户端,所以请在javascript中发布代码。
解决方案
function gmod(n,m){
返回((n%m)+ m)%m;
}
function kuwaiticalendar(adjust){
var today = new Date ();
如果(调整){
adjustmili = 1000 * 60 * 60 * 24 * adjust;
todaymili = today.getTime()+ adjustmili;
today = new 日期(todaymili);
}
day = today.getDate();
month = today.getMonth();
year = today.getFullYear();
m =月+ 1;
y =年;
if (m <3){
y - = 1 ;
m + = 12 ;
}
a = 数学 .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 = 数学 .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 = 数学 .floor((bb-122。 1 )/ 365. 25 跨度>);
dd = 数学 .floor( 365 .25 * cc);
ee = 数学 .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;
if (adjust){
wd = gmod(jd + 1-adjust, 7 跨度>)+ 1;
} 其他 {
wd = gmod(jd + 1, 7 )+ 1;
}
iyear = 10631 ./ 30。;
epochastro = 1948084 ;
epochcivil = 1948085 ;
shift1 = 8 .01 / 60。;
z = jd-epochastro;
cyc = 数学 .floor(z / 10631。);
z = z-10631 * cyc;
j = 数学 .floor((z-shift1)/ iyear);
iy = 30 * cyc + j;
z = z-Math.floor(j * iyear + shift1);
im = 数学 .floor((z + 28。 5001 )/ 29. 5 跨度>);
if (im == 13 )im = 12 跨度>;
id = z-Math.floor( 29 .5001 * im-29);
var myRes = new 数组( 8 );
myRes [ 0 ] = day; // 计算日期(CE)
myRes [ 1 ] = month-1; // 计算月份(CE)
myRes [ 2 ] =年; // 计算年份(CE)
myRes [ 3 ] = jd-1; // julian day number
myRes [ 4 ] = wd-1; // 工作日编号
myRes [ 5 ] = id; // 伊斯兰日期
myRes [ 6 ] = im-1; // 伊斯兰月
myRes [ 7 ] = iy; // 伊斯兰年
返回 myRes;
}
function writeIslamicDate(调整){
var wdNames = new 数组( Ahad, Ithnin, Thulatha, Arbaa, Khams, Jumuah, Sabt 跨度>);
var iMonthNames = new 数组( Muharram, < span class =code-string> Safar, Rabi'ul Awwal , Rabi'ul Akhir,
Jumadal Ula, Jumadal Akhira , Rajab, Sha'ban,
Ramadan, Shawwal, Dhul Qa'ada, Dhul Hijja);
var iDate = kuwaiticalendar(调整);
var outputIslamicDate = wdNames [iDate [ 4 ]] + ,
+ iDate [ 5 ] + + iMonthNames [iDate [ 6 ]] + + iDate [ 7 ] + AH;
return outputIslamicDate;
}
积分
http://www.al-habib.info/ islamic-calendar / hijricalendartext.htm [ ^ ]
Hi i had the code in server side for Gregorian date to Hijridate but for better performance i need it to be in client side ,so please post the code in javascript for this.
解决方案
function gmod(n,m){ return ((n%m)+m)%m; } function kuwaiticalendar(adjust){ var today = new Date(); if(adjust) { adjustmili = 1000*60*60*24*adjust; todaymili = today.getTime()+adjustmili; 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; if(adjust) { 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; }
Credits to
http://www.al-habib.info/islamic-calendar/hijricalendartext.htm[^]
这篇关于嗨我需要在javascript中将Hgorridate的格里高利日期代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文