JavaScript gets the current date's lunar date code

Source: Internet
Author: User
Tags getdate

JavaScript code

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179-18 0 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198-199 /* Set Lunar Date/*    var calendardata=new Array (100);    var madd=new Array (12);    var numstring= "1,234,567,890";    var monstring= "234,567,890 Winter Wax";    var cyear,cmonth,cday,thedate;   //Lunar calendar can only be 29 or 30 days per month, a year with 12 (or 13) bits, from high to low, corresponding bit of 1 for 30 days, otherwise 29 days    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,0X 526,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);     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 () {&N bsp;  thedate= (arguments.length!=3)? New Date (): new Date (arguments[0],arguments[1],arguments[2]);    var total,m,n,k;    var isend=false;    var tmp=thedate.getyear ();    if (tmp<1900) {   tmp+=1900   }    total= (tmp-1921) *365+math.floor ( tmp-1921)/4 +madd[thedate.getmonth ()]+thedate.getdate ()-38;    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=1921 + 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--;    }   }   }    function getcdatestring () {   var tmp= "";    if (cmonth&lt 1) {   tmp+= "(Leap)"    Tmp+=monstring.charat (-cmonth-1)   }else{   tmp+= Monstring.charat (cMonth-1);   }    tmp+= "month";    tmp+= (CDAY≪11)? " The first ":((cday<20)?" Ten ":((cday<30)?" 20 ":" 30 "));    if (cday%10!=0| | cday==10) {   Tmp+=numstring.charat ((cDay-1)%10);   }    return tmp;   }    function Getlunarday (solaryear,solarmonth,solarday) {  //solaryear = Solaryear <1900? (1900+solaryear): solaryear;    if (solaryear<1921 | | solaryear>2020) {   return "";   }else{   solarmonth = (parseint (solarmonth) >0)? (solarMonth-1): 11;    e2c (Solaryear,solarmonth,solarday);    return getcdatestring ();   }   }    var d=new Date ();    var yy=d.getfullyear ();    var mm=d.getmonth () +1;    var dd=d.getdate ();    var ww=d.getday ();    var ss=parseint (D.gettime ()/1000);    if (yy<100) yy= "+yy";    function showcal () {   var Nongli = Getlunarday (YY,MM,DD);    return Nongli;   }   /* Lunar set end*/

Call

The

code is as follows:


$ (' #tianqi h5 '). Text (showcal ());


Effect:

September 11 is the day's lunar date

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.