首頁 >web前端 >js教程 >很好用的js日曆演算法詳細程式碼_javascript技巧

很好用的js日曆演算法詳細程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:40:481047瀏覽

複製程式碼 程式碼如下:


       var月球資訊= 新陣列(
0x04bd8, 0x04ae0, 0x0a570, 0x054 056a0, 0x09ad0, 0x055d2,
0x 04ae0、0x0a5b6、0x0a4d0、0x0d250、0x1d255、0x0b540、0x0d6a0、0x0ada2 , 0x095b0, 0x14977, 0x0 , 6566、0x0d4a0、0x0ea50、0x06e95、0x05ad0、0x02b60、0x186e3、0x092e0、0x1c8d7、0x0c950 ,
0x04100x 1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550 , 5355、0x04da0、0x0a5d0、0x14573、0x052d0、0x0a9a8、0x0e950、0x06aa0、
x0d950、0x05b57、0x056a0、
0x096d0、0x04dd5、0x04ad0、 d0 、0x0d4d4、0x0d250、0x0d558、0x0b540、0x0b5a0、0x195a6、
0x095b0、0x049b0、60x0a974、0x095b0、0x049b0、60x ab60、0x09570、
0x04af5、0x04970、0x064b0、0x074a3、0x0ea50、 b58 , 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
0x0c960, 0x0d954, 0x0d4a0, 0x0da50,0 0x07552、0056x 、
0x0a950、0x0b4a0、0x0baa4、0x0ad50、0x055d9、0x04ba0、0x0a5b0、6 、0x052b0、0x0a930、
0x07954、0x06aa0、0x0ad50、0x05b52、0x04b60、0x0a6e6、aa 0x0a4e0、0x04b60、0x0a6e6、aa 0x0a4e0、0x0d260、00xea 0x096d0、0x04bd7、0x04ad0、0x0a4d0、0x1d0b6、0x0d250、0x0d520、0x 0dd45,
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, = new Array("老鼠", "牛", "老虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞”、“狗”、“豬”);
        var Gan = new Array("甲", "B", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸");
        varzhi = new Array("子", "醜", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌」、「亥」);
        var now = new Date() ;
        var SY = now.getFullYear();
        var SM = now.getMon     //==== 建立offset 傳回幹支, 0=甲子 
        function cyclal(num) { return (Gan[num % 10]zhi[num % 12]) }
 的總天數 
        function lYearDays(y) {
            8; i >>= 1) sum = (lunarInfo[y - 1900] & i) ? 1 : 0
            return (sum LeapDays(y))
        } if (leapMonth(y)) return ((lunarInfo[y - 1900] & 0x10000) ? 30 : 29)
                 //=== = 傳回農曆y 年閏哪個月1-12 , 沒閏傳回0 
        function LeapMonth(y) { return (lunarInfo[y - 1900] & 0xf) ; === ================================== 傳回農曆y 年月的總天數
        functionmonthDays (y, m) { return ((lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29) }

        //==== 計算農曆, 傳入日期物件, 傳回農曆日期物件 
        //  >        function Lunar(objDate) {
            var i, leap = 0, temp = 0             var offset = (objDate - baseDate) / 86400000

            this.dayCyl = offset 40
            的; i 0; i ) {
                temp = lYearDays(i)
                offset -= temp
             >            if (offset                                this.monCyl - = 12
            }

             
            leap = leapMonth(i) //閏哪個月 
           = false

            for (i = 1; i 0; i ) {
                 if (leap > 0 && i == (leap 1) && this. isLeap == false)
                { --i; this.isLeap = true; temp = leapDay                { temp = monthDays(this.year, i); }

                //解除閏月 
             🎜>
                的set -= temp
                   .isLeap == false) this.monCyl
            }

                     if (this.isLeap)
                { this .isLeap = false; }
                else
                     if (offset
            this.month = i
          

        function YYMMDD() {
            var cl = '';
            if (now.getDay() == 6) cl = '';
            return (cl SY '年' (SM 1) '月' SD '日
 weekday() {
            var day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); ';
            if (now.getDay() == 0) cl = '';
            if (now.getDay() == 6) cl = ''';
; return (cl day[now.getDay()] '
');
        }
        //======       var nStr1 = new Array('日', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十');
            var nStr2 = new Array('初', '十', '堿', '卅', ' ');
     if (m > 10) { s = '十' nStr1 [m - 10] } else { s = nStr1[m] } s = '月'
            switch (d) {
        switch (d) {
                     case 20: s = '二十'; break;
                case 30: s = '三十'; break;
      s = nStr1[d % 10] ;
            }
            return (s);
   🎜>            var sDObj = new Date(SY, SM, SD);
            var lDObj = new Lunar(sDObj);
            var cl = '' '閏':' ') cld[d].lMonth ' 月' cld[d].lDay ' 日 
            var tt = '農曆' cDay(lDObjmonth, lbj.day); tt '
');
        }
        function solarDay3() {
            var sTermInfo = new Array(0, 21208, 42467, 138383838383, 17,42467,8383 21, 173149,

195551, 218072, 240693, 263343, 285989 , 308563, 331033, 353350, 375494, 397447, 419210,

440795, 462224, 483532, 504755 solarTerm = new Array("小寒", "大寒", "立春", "雨水", "驚蟄", "春分", "清明", "穀雨", "驚蟄", "小滿", "芒種", "夏至", "小暑", "大暑", "立秋", "處暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至")
            var lFtv = new Array("0101*春節", "0505 端午", "0707 七夕情人節", "0715 中元節", "0815 中秋節", "0909 重陽節", "1208 臘八節", "1224 小年", "0100*除夕")
            var sFtv = new Array("0101*元旦", "0214 情人節", "0308 婦女節", "0312 植樹節", "03155" "0501 勞動節", "0504 青年節", "0512 護士節", "0601 兒童節", "0701 建黨節香港回歸紀念",
"0801 建軍節", "0808 父親節", " 0909 南晟網週年紀念日", "0910 教師節", "0928 孔子誕辰", "1001*國慶日",
"1006 老人節", "1024 聯合國日", "1112 孫中山誕辰", " 1220 澳門回歸紀念", "1225 聖誕節", "1226 毛主席誕辰")

            new Lunar(sDObj);
            var lDPOS = new Array(3)
            var 排           //農曆節日 
            for (i in lFtv)
                   tmp1 = Number(RegExp.$1) - lDObj.month
                    tmp2 = Number(RegExp.    if (tmp1 == 0 && tmp2 == 0) lunarFestival = RegExp.$4
                }
            //國曆節慶 
            for (i in sFtv)                     tmp1 = Number(RegExp.$1) - (SM 1)                     if (tmp1 == 0 && tmp2 == 0) solarFestival = RegExp.$4
                }
            // 節氣 
            tmp1 = new Date((31556925974.7 * (9910)7 *209974.7 *(9990)7 *20990% 00, 0, 6, 2, 5))
tmp2 = tmp1.getUTCDate()
            if (tmp2 == SD) 節氣= 節氣[SM * 2 1]
    0) sTermInfo[SM * 2] * 60000 ) Date.UTC(1900, 0, 6, 2, 5))
            tmp2 = tmp1.getUTCDate()    
if (solarTerms == '' && SolarFestival == '' && lunarFestival == '')
                          節慶= '' 節氣' ' 節氣' ' 農曆節'';

            var cl = '';
            return (cl Festival '
');
        }
       document.write(YYMMDD() ' ' weekday() ' ' SolarDay2() ' ' SolarDay3()); 
        }

        setCalendar();         function getNowMonthDays(year, Month) {
            var isy = false;
          年份isy = true;
            切換(月){
                             案例5:
                案例7:                案例12:
                   使用 31;
               :
                               回30;
                狀況2:
                        28:29;
            }
        }
        //取得此月一號為週數
        function getStartWeek() {
        var week = now.getDay() 1; //今天週幾
            var startweek = week 7 - tempnum;
           >
        //取得農曆
        function getSolarDay(year, month, day) {
            var sDObj = new Date(year, month, day);
           //農曆BB' (cld[d].isLeap?'閏':' ') cld[d].lMonth ' 月' cld[d].lDay ' 日 
            return cDay(lDObj.month, lDObj.day 月視圖
        function showMonth() {
            debugger;
             var startweek = getStartWeek();
            var html = " 星期一 星期二 星期三 星期四 星期五 星期六 星期日星期四星期五 星期六 星期日 td> ";
            var index = 0;
                html = " " ; index ;
            }
            for (var i = 1; i                     html = " ";
                } html = "" i "
" getSolarDay(SY, SM           }
for (var i = 0; i                 if (index % 7 == 0) {                 html = " " ; index ;
            }
            html = "        }

   



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn