源码论坛,商业源码下载,尽在锦尚中国商业源码论坛

标题: 能在任何页面上显示具体时间 日期 农历的代码 [打印本页]

作者: administrator    时间: 2011-10-4 00:24
标题: 能在任何页面上显示具体时间 日期 农历的代码
  1. <SCRIPT language=JavaScript>
  2. var lunarInfo=new Array(
  3. 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
  4. 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
  5. 0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
  6. 0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
  7. 0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
  8. 0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
  9. 0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
  10. 0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
  11. 0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
  12. 0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
  13. 0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
  14. 0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
  15. 0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
  16. 0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
  17. 0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0,
  18. 0x14b63);
  19. var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  20. var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
  21. var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
  22. var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');
  23. var nStr2 = new Array('初','十','廿','卅',' ');
  24. var nStr3 = new Array('日','一','二','三','四','五','六','七','八','九','十','十一','十二');
  25. function lYearDays(y) {
  26.    var i, sum = 348;
  27.    for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0;
  28.    return(sum+leapDays(y));
  29. }
  30. function leapDays(y) {
  31.    if(leapMonth(y))  return((lunarInfo[y-1900] & 0x10000)? 30: 29);
  32.    else return(0);
  33. }
  34. function leapMonth(y) {
  35.    return(lunarInfo[y-1900] & 0xf);
  36. }
  37. function monthDays(y,m) {
  38.    return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 );
  39. }
  40. function Lunar(objDate) {
  41.    var i, leap=0, temp=0;
  42.    var offset   = (Date.UTC(objDate.getFullYear(),objDate.getMonth(),objDate.getDate()) - Date.UTC(1900,0,31))/86400000;
  43.    this.dayCyl = offset + 40;
  44.    this.monCyl = 14;
  45.    for(i=1900; i<2050 && offset>0; i++) {
  46.       temp = lYearDays(i);
  47.       offset -= temp;
  48.       this.monCyl += 12;
  49.    }
  50.    if(offset<0) {
  51.       offset += temp;
  52.       i--;
  53.       this.monCyl -= 12;
  54.    }
  55.    this.year = i;
  56.    this.yearCyl = i-1864;
  57.    leap = leapMonth(i); //闰哪个月
  58.    this.isLeap = false;
  59.    for(i=1; i<13 && offset>0; i++) {
  60.       //闰月
  61.       if(leap>0 && i==(leap+1) && this.isLeap==false)
  62.          { --i; this.isLeap = true; temp = leapDays(this.year); }
  63.       else
  64.          { temp = monthDays(this.year, i); }
  65.       if(this.isLeap==true && i==(leap+1)) this.isLeap = false;
  66.       offset -= temp;
  67.       if(this.isLeap == false) this.monCyl ++;
  68.    }
  69.    if(offset==0 && leap>0 && i==leap+1)
  70.       if(this.isLeap)
  71.          { this.isLeap = false; }
  72.       else
  73.          { this.isLeap = true; --i; --this.monCyl;}
  74.    if(offset<0){ offset += temp; --i; --this.monCyl; }
  75.    this.month = i;
  76.    this.day = offset + 1;
  77. }
  78. function solarDays(y,m) {
  79.    if(m==1)
  80.       return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28);
  81.    else
  82.       return(solarMonth[m]);
  83. }
  84. function cyclical(num) {
  85.    return(Gan[num%10]+Zhi[num%12]);
  86. }
  87. function calElement(sYear,sMonth,sDay,week,lYear,lMonth,lDay,isLeap,cYear,cMonth,cDay) {
  88.       this.isToday    = false;
  89.       //公历
  90.       this.sYear      = sYear;
  91.       this.sMonth     = sMonth;
  92.       this.sDay       = sDay;
  93.       this.week       = week;
  94.       //农历
  95.       this.lYear      = lYear;
  96.       this.lMonth     = lMonth;
  97.       this.lDay       = lDay;
  98.       this.isLeap     = isLeap;
  99.       //干支
  100.       this.cYear      = cYear;
  101.       this.cMonth     = cMonth;
  102.       this.cDay       = cDay;
  103. }
  104. function calendar(y,m) {
  105.    var sDObj, lDObj, lY, lM, lD=1, lL, lX=0, tmp1, tmp2;
  106.    var lDPOS = new Array(3);
  107.    var n = 0;
  108.    var firstLM = 0;
  109.    sDObj = new Date(y,m,1,0,0,0,0);    //当月一日日期
  110.    this.length    = solarDays(y,m);    //公历当月天数
  111.    this.firstWeek = sDObj.getDay();    //公历当月1日星期几
  112.    for(var i=0;i<this.length;i++) {
  113.       if(lD>lX) {
  114.          sDObj = new Date(y,m,i+1);    //当月一日日期
  115.          lDObj = new Lunar(sDObj);     //农历
  116.          lY    = lDObj.year;           //农历年
  117.          lM    = lDObj.month;          //农历月
  118.          lD    = lDObj.day;            //农历日
  119.          lL    = lDObj.isLeap;         //农历是否闰月
  120.          lX    = lL? leapDays(lY): monthDays(lY,lM); //农历当月最後一天
  121.          if(n==0) firstLM = lM;
  122.          lDPOS[n++] = i-lD+1;
  123.       }
  124.       this[i] = new calElement(y, m+1, i+1, nStr1[(i+this.firstWeek)%7],
  125.                                lY, lM, lD++, lL,
  126.                                cyclical(lDObj.yearCyl) ,cyclical(lDObj.monCyl), cyclical(lDObj.dayCyl++) );
  127.    }
  128. }
  129. function cDay(d){
  130.    var s;
  131.    switch (d) {
  132.       case 10:
  133.          s = '初十'; break;
  134.       case 20:
  135.          s = '二十'; break;
  136.          break;
  137.       case 30:
  138.          s = '三十'; break;
  139.          break;
  140.       default :
  141.          s = nStr2[Math.floor(d/10)];
  142.          s += nStr1[d%10];
  143.    }
  144.    return(s);
  145. }
  146. function cMon(d){
  147.    var s;
  148.    switch (d) {
  149.       case 1:
  150.          s = '正'; break;
  151.       case 12:
  152.          s = '腊'; break;
  153.       default :
  154.          s = nStr3[d];
  155.      break;
  156.    }
  157.    return(s);
  158. }
  159. var ctime=new Date();
  160. var nYear = ctime.getYear();
  161. var nMonth = ctime.getMonth();
  162. var d = ctime.getDate() - 1;
  163. var ddd =new calendar(nYear,nMonth);
  164. var bsWeek=ddd[d].week;
  165. var bsDate=ddd[d].sYear+"年"+ddd[d].sMonth+"月";
  166. var bsDate2=ddd[d].sDay+"日";
  167. var bsYear=ddd[d].cYear + "年" + cMon(ddd[d].lMonth) + "月" + cDay(ddd[d].lDay);
  168. function CAL(){
  169. document.write("今天是:&nbsp;&nbsp;"+bsDate+bsDate2);
  170. document.write("&nbsp;&nbsp;星期" + bsWeek+"&nbsp;&nbsp;");
  171. document.write(bsYear);
  172. }
  173. CAL();
  174. </script>
复制代码
将以上代码复制粘贴到<body></body>之间任何一个位置即可!



作者: rj366    时间: 2011-10-15 22:13
真的很不错
作者: kvsti    时间: 2011-10-17 08:46
行,有意义,我顶 谢谢您了












意外-意外资讯:http://www.xihuanfou.com/zt/yiwai.html
作者: safeidc    时间: 2011-10-26 11:07
不错
作者: conglin58    时间: 2011-10-29 05:38
代码好长啊!有没有短一点的?
作者: 代号k    时间: 2011-11-2 16:10
...................












www.soyangsyl.com搜羊娱-乐新闻网 www.kooshu.com在线笑话
作者: 网络江河chs    时间: 2011-11-16 18:56
强烈支持。












什么减肥药效果最好
http://www.68qutao.com

作者: lelaitao    时间: 2011-11-24 15:17
代码收藏了。
作者: 52jscn8975    时间: 2011-12-7 21:53
好厉害呀
作者: 楼羽二    时间: 2011-12-9 04:02
不错!不错!不错!












减肥药哪种好  www.wosouwosou.com 瘦身减肥
爆真秀 艾洛廖 www.cityladys.com www.jingwushiping.com
都市丽人 www.arnueit.com
淘西施 淘宝导购 www.taoxichi.com





欢迎光临 源码论坛,商业源码下载,尽在锦尚中国商业源码论坛 (https://bbs.52jscn.com/) Powered by Discuz! X3.3