判断节假日 有阳历的日期 也有阴历的日期 所以要获得两个日期 加以判断
1 $(function () { 2 3 // 找到阴历 的 月 日 4 var CalendarData=new Array(100); 5 var madd=new Array(12); 6 // var tgString="甲乙丙丁戊己庚辛壬癸"; 7 // var dzString="子丑寅卯辰巳午未申酉戌亥"; 8 var numString="一二三四五六七八九十"; 9 var monString="正二三四五六七八九十冬腊"; 10 var weekString="日一二三四五六"; 11 // var sx="鼠牛虎兔龙蛇马羊猴鸡狗猪"; 12 var cYear,cMonth,cDay,TheDate; //阴历年月日变量 13 CalendarData = new Array(0xA4B,0x5164B,0x6A5,0x6D4,0x415B5,0x2B6,0x957,0x2092F,0x497,0x60C96,0xD4A,0xEA5,0x50DA9,0x5AD,0x2B6,0x3126E, 0x92E,0x7192D,0xC95,0xD4A,0x61B4A,0xB55,0x56A,0x4155B, 0x25D,0x92D,0x2192B,0xA95,0x71695,0x6CA,0xB55,0x50AB5,0x4DA,0xA5B,0x30A57,0x52B,0x8152A,0xE95,0x6AA,0x615AA,0xAB5,0x4B6,0x414AE,0xA57,0x526,0x31D26,0xD95,0x70B55,0x56A,0x96D,0x5095D,0x4AD,0xA4D,0x41A4D,0xD25,0x81AA5,0xB54,0xB6A,0x612DA,0x95B,0x49B,0x41497,0xA4B,0xA164B, 0x6A5,0x6D4,0x615B4,0xAB6,0x957,0x5092F,0x497,0x64B, 0x30D4A,0xEA5,0x80D65,0x5AC,0xAB6,0x5126D,0x92E,0xC96,0x41A95,0xD4A,0xDA5,0x20B55,0x56A,0x7155B,0x25D,0x92D,0x5192B,0xA95,0xB4A,0x416AA,0xAD5,0x90AB5,0x4BA,0xA5B, 0x60A57,0x52B,0xA93,0x40E95); 14 madd[0]=0; 15 madd[1]=31; 16 madd[2]=59; 17 madd[3]=90; 18 madd[4]=120; 19 madd[5]=151; 20 madd[6]=181; 21 madd[7]=212; 22 madd[8]=243; 23 madd[9]=273; 24 madd[10]=304; 25 madd[11]=334; 26 27 function GetBit(m,n){ 28 return (m>>n)&1; 29 } 30 function e2c(){ 31 TheDate= (arguments.length!=3) ? new Date() : new Date(arguments[0],arguments[1],arguments[2]); 32 var total,m,n,k; 33 var isEnd=false; 34 var tmp=TheDate.getYear(); 35 if(tmp<1900){ 36 tmp+=1900; 37 } 38 total=(tmp-1921)*365+Math.floor((tmp-1921)/4)+madd[TheDate.getMonth()]+TheDate.getDate()-38; 39 40 if(TheDate.getYear()%4==0&&TheDate.getMonth()>1) { 41 total++; 42 } 43 for(m=0;;m++){ 44 k=(CalendarData[m]<0xfff)?11:12; 45 for(n=k;n>=0;n--){ 46 if(total<=29+GetBit(CalendarData[m],n)){ 47 isEnd=true; break; 48 } 49 total=total-29-GetBit(CalendarData[m],n); 50 } 51 if(isEnd) break; 52 } 53 cYear=1921 + m; 54 cMonth=k-n+1; 55 cDay=total; 56 if(k==12){ 57 if(cMonth==Math.floor(CalendarData[m]/0x10000)+1){ 58 cMonth=1-cMonth; 59 } 60 if(cMonth>Math.floor(CalendarData[m]/0x10000)+1){ 61 cMonth--; 62 } 63 } 64 } 65 66 function GetcDateString(){ 67 var tmp=""; 68 //tmp+=tgString.charAt((cYear-4)%10); 69 // tmp+=dzString.charAt((cYear-4)%12); 70 // tmp+="("; 71 // tmp+=sx.charAt((cYear-4)%12); 72 // tmp+=")年 "; 73 if(cMonth<1){ 74 // tmp+="(闰)"; 75 tmp+=monString.charAt(-cMonth-1); 76 }else{ 77 tmp+=monString.charAt(cMonth-1); 78 } 79 tmp+="月"; 80 tmp+=(cDay<11)?"初":((cDay<20)?"十":((cDay<30)?"廿":"三十")); 81 if (cDay%10!=0||cDay==10){ 82 tmp+=numString.charAt((cDay-1)%10); 83 } 84 return tmp; 85 } 86 87 function GetLunarDay(solarYear,solarMonth,solarDay){ 88 //solarYear = solarYear<1900?(1900+solarYear):solarYear; 89 if(solarYear<1921 || solarYear>2222){ 90 return ""; 91 }else{ 92 solarMonth = (parseInt(solarMonth)>0) ? (solarMonth-1) : 11; 93 e2c(solarYear,solarMonth,solarDay); 94 return GetcDateString(); 95 } 96 } 97 //获取今天的阳历年月日 98 //var D=new Date(); 99 var D= new Date(2021,1,11); 100 var yy=D.getFullYear(); 101 var mm=D.getMonth()+1; 102 var dd=D.getDate(); 103 var ww=D.getDay(); 104 var ss=parseInt(D.getTime() / 1000); 105 if (yy<100) yy="19"+yy; 106 //获取阴历的 月 日 107 GetLunarDay(yy,mm,dd); 108 var yMonth=""; //阴历 月份 109 if(cMonth<1){ 110 yMonth=monString.charAt(-cMonth-1); 111 }else{ 112 yMonth=monString.charAt(cMonth-1); 113 } 114 var yDay=""; //阴历 日期 115 yDay+=(cDay<11)?"初":((cDay<20)?"十":((cDay<30)?"廿":"三十")); 116 if (cDay%10!=0||cDay==10){ 117 yDay+=numString.charAt((cDay-1)%10); 118 } 119 console.log(D); 120 console.log(mm+"-"+dd); 121 console.log(yMonth+"-"+yDay); 122 // 元旦 1天 1-1 123 // //;zhi (二)春节,除夕 到初六 124 // (三)清明节,放假1天(农历清明当日); 算不出来的 125 // (四)劳动节,放假1天(5月1日); 阳历 5-1 126 // (五)端午节,放假1天(农历端午当日);阴历五月五号 127 // (六)中秋节,放假1天(农历中秋当日);阴历八月15 128 // (七)国庆节,放假3天(10月1日、2日、3日)。阳历 10-1 -10-7 129 130 131 if(mm==‘1‘&&dd==‘1‘){ 132 console.log("元旦"); 133 }else if(mm==‘5‘&&dd==‘1‘){ 134 console.log("劳动节"); 135 }else if(mm==‘10‘&&(dd==‘1‘||dd==‘2‘||dd==‘3‘||dd==‘4‘||dd==‘5‘||dd==‘6‘||dd==‘7‘)){ 136 console.log("国庆节"); 137 }else if(mm==‘五‘&&dd==‘初五‘){ 138 console.log("端午节"); 139 }else if(mm==‘八‘&&dd==‘十五‘){ 140 console.log("中秋节"); 141 }else if(mm==‘腊‘&&dd==‘三十‘||mm==‘一‘&&(dd==‘初一‘||dd==‘初二‘||dd==‘初三‘||dd==‘初四‘||dd==‘初五‘||dd==‘初六‘)){ 142 console.log("春节"); 143 } 144 145 146 }) 147 148