📄 lunar.js
字号:
var qk=int2( (ob.d0-SSQ.ZQ[0]-7)/15.2184 ); if(qk<23 && ob.d0>=SSQ.ZQ[qk+1]) qk++; //节气的取值范围是0-23
if(ob.d0==SSQ.ZQ[qk]) ob.Ljq=obb.jqmc[qk];
else ob.Ljq='';
ob.yxmc = ob.yxjd = ob.yxsj ='';//月相名称,月相时刻(儒略日),月相时间串
ob.jqmc = ob.jqjd = ob.jqsj ='';//定气名称,节气时刻(儒略日),节气时间串
//干支纪年处理
//以下被注释的两行以正月初一定年首
//for(j=mk;j>=0;j--) if(SSQ.ym[j]=="正月") break;
//D=j<0 ? SSQ.HS[2]-365 : SSQ.HS[j]+5810; //该年春节与1984年平均春节(立春附近)相差天数估计
D = SSQ.ZQ[3] + (ob.d0<SSQ.ZQ[3]?-365:0) + 365.25*16-35; //以立春为界定纪年
ob.Lyear = Math.floor(D/365.2422+0.5); //农历纪年(10进制,1984年起算)
D = ob.Lyear +9000;
ob.Lyear2 = obb.Gan[D%10]+obb.Zhi[D%12]; //干支纪年
//纪月处理,1998年12月7(大雪)开始连续进行节气计数,0为甲子
mk = int2( (ob.d0 - SSQ.ZQ[0])/30.43685 ); if(mk<12 && ob.d0>=SSQ.ZQ[2*mk+1]) mk++; //相对大雪的月数计算,mk的取值范围0-12
D = mk + int2( (SSQ.ZQ[12]+390)/365.2422 )*12 + 900000; //相对于1998年12月7(大雪)的月数,900000为正数基数
ob.Lmonth = D%12;
ob.Lmonth2 = obb.Gan[D%10]+obb.Zhi[D%12];
//纪日,2000年1月7日起算
D = ob.d0 - 6 + 9000000;
ob.Lday2 = obb.Gan[D%10]+obb.Zhi[D%12];
//星座
mk = int2( (ob.d0-SSQ.ZQ[0]-15)/30.43685 ); if( mk<11 && ob.d0>=SSQ.ZQ[2*mk+2] ) mk++; //星座所在月的序数,(如果j=13,ob.d0不会超过第14号中气)
ob.XiZ = obb.XiZ[(mk+12)%12]+'座';
//回历
obb.getHuiLi(ob);
//节日
ob.A = ob.B = ob.C = ''; ob.Fjia = 0;
obb.getDayName(ob,ob); //公历
obb.getDayNameL(ob,ob);//农历
}
//以下是月相与节气的处理
var d, xn, jd2= Bd0+JD.deltatT2(Bd0)-8/24;
//月相查找
w = XL.MS_aLon( jd2/36525,10,3 );
w = int2( (w-0.78)/Math.PI*2 ) * Math.PI/2;
do {
d = obb.so_accurate(w);
D = int2(d+0.5);
xn = int2(w/pi2*4+4000000.01)%4;
w += pi2/4;
if(D>=Bd0+Bdn) break;
if(D<Bd0) continue;
ob = this.lun[D-Bd0];
ob.yxmc = obb.yxmc[xn]; //取得月相名称
ob.yxjd = d;
ob.yxsj = JD.timeStr(d);
} while(D+5<Bd0+Bdn);
//节气查找
w = XL.S_aLon( jd2/36525, 3 );
w = int2( (w-0.13)/pi2*24 ) *pi2/24;
do {
d = obb.qi_accurate(w);
D = int2(d+0.5);
xn = int2(w/pi2*24+24000006.01)%24;
w += pi2/24;
if(D>=Bd0+Bdn) break;
if(D<Bd0) continue;
ob = this.lun[D-Bd0];
ob.jqmc = obb.jqmc[xn]; //取得节气名称
ob.jqjd = d;
ob.jqsj = JD.timeStr(d);
} while(D+12<Bd0+Bdn);
}
//Lunar的成员函数
function yueLiHTML(By,Bm,curJD){ //html月历生成,结果返回在lun中,curJD为当前日期(用于设置今日标识)
var sty_head =' style="font-family: 宋体; font-size: 14px; text-align: center; background-color: #E0E0FF; color: #000000; font-weight: bold" ';
var sty_body =' style="font-family: 宋体; font-size: 12px; text-align: center " ';
var sty_date =' style="font-family: Arial Black; text-align: center;font-size: 20px" ';
var sty_date2=' style="font-family: Arial Black; text-align: center;font-size: 20px; color: #FF0000" ';
var sty_cur =' style="background-color:#90D050" ';
var i,j, c,c2, cr="",isM;
var ob; //日历物件
this.yueLiCalc(By,Bm); //农历计算
//年份处理
c = this.nianhao +' 农历'+this.Ly+'年【'+this.ShX+'年】'; //干支纪年
if(c.length>33) c = '<span style="font-size:12px">'+c+'</span>';
else c = '<span style="font-size:16px;font-weight:bold">'+c+'</span>';
this.pg0 = c;
//月历处理
var ta0='<tr>'
+'<td'+sty_head+'width="%14">日</td>'
+'<td'+sty_head+'width="%14">一</td>'
+'<td'+sty_head+'width="%14">二</td>'
+'<td'+sty_head+'width="%14">三</td>'
+'<td'+sty_head+'width="%14">四</td>'
+'<td'+sty_head+'width="%14">五</td>'
+'<td'+sty_head+'width="%14">六</td><tr>';
for(i=0;i<this.dn;i++){ //遍历本月各日(公历)
//生成i日的日历页面
ob = this.lun[i];
if(!i){ for(j=0;j<this.w0;j++) cr+='<td'+sty_body+'></td>'; } //首行前面的空单元格
c = '', isM = ''; //文字格式控制项
if(ob.A) c += '<font color=red>' +obb.substr2(ob.A,4,'..')+'</font>';
if(!c && ob.B) c = '<font color=blue>'+obb.substr2(ob.B,4,'..')+'</font>';
if(!c && ob.Ldc=="初一") c = ob.Lleap + ob.Lmc +'月'+ (ob.Ldn==30?'大':'小'); //农历历月(闰月及大小等)
if(!c) c = ob.Ldc; //取农历日名称
if(ob.yxmc=="朔") isM = '<font color=#505000>●</font>'; //取月相
if(ob.yxmc=="望") isM = '<font color=#F0B000>●</font>'; //取月相
if(ob.yxmc=="上弦") isM = '<font color=#F0B000><b>∪</b></font>';
if(ob.yxmc=="下弦") isM = '<font color=#F0B000><b>∩</b></font>';
if(ob.jqmc) isM += '<font color=#00C000>◆</font>'; //定气标记
if(ob.Fjia) c2 = sty_date2; //节日置红色
else c2 = sty_date;
c2 += ' onmouseover="showMessD('+i+')"';
c2 += ' onmouseout ="showMessD(-1)"';
c2 = '<span' + c2 + '>' +ob.d + '</span>'; //公历的日名称
if(ob.d0 == curJD) c2='<span'+sty_cur+'>'+c2+'</span>'; //今日标识
cr += '<td'+sty_body+'width="14%">'+c2+'<br>'+isM+c+'</td>';
if(i==this.dn-1) { for(j=0;j<6-ob.week;j++) cr+='<td'+sty_body+'></td>'; } //末行后面的空单元格
if(i==this.dn-1||ob.week==6) ta0+='<tr>'+cr+'</tr>', cr="";
}
this.pg1='<table border=0 cellpadding=3 cellspacing=1 width="100%">'+ta0+'</table>';
var b2='',b3='',b4='';
for(i=0;i<this.dn;i++){
ob=this.lun[i];
c = i+1; if(c<10) c=' '+c;
//if(ob.Ldc =='初一') b1 += c +'日 '+ob.Lleap+ob.Lmc+'月' + (ob.Ldn==30?'大':'小')+' ';
if(ob.yxmc=='朔' ||ob.yxmc=="望" ) b2 += c +'日 ' + ob.yxsj + ob.yxmc + '月 ';
if(ob.yxmc=='上弦'||ob.yxmc=="下弦") b3 += c +'日 ' + ob.yxsj + ob.yxmc + ' ';
if(ob.jqmc) b4 += c +'日 ' + ob.jqsj + ob.jqmc + ' ';
}
this.pg2 = b2+'<br>'+b3+'<br>'+b4;
}
//月历类件
function Lunar(){
var i;
this.lun=new Array();
for(i=0;i<31;i++) this.lun[i] = new Object();
this.lun.dn=0;
this.yueLiCalc=yueLiCalc;
this.yueLiHTML=yueLiHTML;
}
/********************
年历HTML生成
*********************/
function nianLiHTML(y){ //html年历生成
var i,j,s='', s1,s2,v;
SSQ.calcY( int2((y-2000)*365.2422+180) );
for(i=0;i<14;i++){
if(SSQ.HS[i+1]>SSQ.ZQ[24]) break; //已包含下一年的冬至
if(SSQ.leap && i==SSQ.leap) s1='闰'; else s1='·';
s1 += SSQ.ym[i]; if(s1.length<3) s1 += '月';
s1 += SSQ.dx[i]>29?'大':'小';
s1 += ' '+JD.setFromJD_str(SSQ.HS[i]+J2000).substr(6,5);
v = obb.so_accurate2(SSQ.HS[i]);
s2 = '('+ JD.setFromJD_str(v+J2000).substr(9,11)+')';
if(int2(v+0.5)!=SSQ.HS[i]) s2 = '<font color=red>'+s2+'</font>';
//v=(v+0.5+J2000)%1; if(v>0.5) v=1-v; if(v<8/1440) s2 = '<u>'+s2+'</u>'; //对靠近0点的加注
s1 += s2;
for(j=0;j<24;j++){
if(SSQ.ZQ[j]<SSQ.HS[i] || SSQ.ZQ[j]>=SSQ.HS[i+1]) continue;
s1 += ' '+obb.jqmc[j]+JD.setFromJD_str(SSQ.ZQ[j]+J2000).subs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -