var calendardata=new array(20); var madd=new array(12); var thedate=new date(); var tgstring="甲乙丙丁戊己庚辛壬癸"; var dzstring="子丑寅卯辰巳午未申酉戌亥"; var numstring="一二三四五六七八九十"; var monstring="正二三四五六七八九十冬腊"; var weekstring="日一二三四五六"; var sx="鼠牛虎兔龙蛇马羊猴鸡狗猪"; var cyear; var cmonth; var cday; var chour; var cdatestring; var datestring; var browser=navigator.appname; //----------------------------------------------------- function init() { calendardata[0]=0x41a95; calendardata[1]=0xd4a; calendardata[2]=0xda5; calendardata[3]=0x20b55; calendardata[4]=0x56a; calendardata[5]=0x7155b; calendardata[6]=0x25d; calendardata[7]=0x92d; calendardata[8]=0x5192b; calendardata[9]=0xa95; calendardata[10]=0xb4a; calendardata[11]=0x416aa; calendardata[12]=0xad5; calendardata[13]=0x90ab5; calendardata[14]=0x4ba; calendardata[15]=0xa5b; calendardata[16]=0x60a57; calendardata[17]=0x52b; calendardata[18]=0xa93; calendardata[19]=0x40e95; madd[0]=0; madd[1]=31; madd[2]=59; madd[3]=90; madd[4]=120; madd[5]=151; madd[6]=181; madd[7]=212; madd[8]=243; madd[9]=273; madd[10]=304; madd[11]=334; } //------------------------------------------------------------ function getbit(m,n) { return (m>>n)&1; } //--------------------------------------------- function e2c() { var total,m,n,k; var isend=false; var tmp=thedate.getyear(); if (tmp<1900)tmp+=1900; total=(tmp-2001)*365+math.floor((tmp-2001)/4)+madd[thedate.getmonth()]+thedate.getdate()-23; if (thedate.getyear()%4==0&&thedate.getmonth()>1)total++; for(m=0;;m++) { k=(calendardata[m]<0xfff)?11:12; for(n=k;n>=0;n--) { if(total<=29+getbit(calendardata[m],n)) { isend=true; break; } total=total-29-getbit(calendardata[m],n); } if(isend)break; } cyear=2001 + m; cmonth=k-n+1; cday=total; if(k==12) { if(cmonth==math.floor(calendardata[m]/0x10000)+1) cmonth=1-cmonth; if(cmonth>math.floor(calendardata[m]/0x10000)+1) cmonth--; } chour=math.floor((thedate.gethours()+3)/2); } //------------------------------------------------------------------- function getcdatestring() { var tmp=""; tmp+=tgstring.charat((cyear-4)%10); //年干 tmp+=dzstring.charat((cyear-4)%12); //年支 tmp+="["; tmp+=sx.charat((cyear-4)%12); tmp+="]年 "; if(cmonth<1) { tmp+="闰"; tmp+=monstring.charat(-cmonth-1); } else tmp+=monstring.charat(cmonth-1); tmp+="月"; tmp+=(cday<11)?"初":((cday<20)?"十":((cday<30)?"廿":"卅")); if(cday%10!=0||cday==10) tmp+=numstring.charat((cday-1)%10); if(chour==13)tmp+="夜"; tmp+=" "+dzstring.charat((chour-1)%12); tmp+="时 "; cdatestring=tmp; return tmp; } //-------------------------------------------------------------------- function getdatestring() { var tmp=""; var t1=thedate.getyear(); if (t1<1900)t1+=1900; tmp+=t1 +"年"+(thedate.getmonth()+1)+"月"+thedate.getdate()+"日 "+"星期"+weekstring.charat(thedate.getday()); datestring=tmp; return tmp; } //-------------------------------------------------------------------- init(); e2c(); getdatestring(); getcdatestring(); document.write(datestring," ",cdatestring);