Use JavaScript to get the lunar date for the current date

Source: Internet
Author: User

Source: http://www.ido321.com/926.html

JavaScript code

   1:/* Set Lunar date * /
   2:var calendardata=New Array (100);
   3:var madd=New Array (12);
   4:var numstring="1,234,567,890";
   5:var monstring="is 234,567,890 winter wax";

6: var cyear,cmonth,cday,thedate;

The lunar calendar can only be 29 or 30 days per month, one year with 12 (or 13) bits, from high to low, corresponding bit 1 for 30 days, otherwise 29 days

7: 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);

   8:  madd[0]=0;
   9:  madd[1]=31;
  Ten:  madd[2]=59;
One   :  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;
  20:
  :function getbit (m,n) {
  :return (m>>n) &1;
  :  }
  :function e2c () {
  :newnew 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 ()- ;
  33:
  :if(Thedate.getyear ()%4==0&&thedate.getmonth () >1) {
  :  total++;
  :  }
  Panax Notoginseng:for(m=0;; m++) {
  :  k= (calendardata[m]<0xfff) 11:12;
  :for  (n=k;n>=0;n--) {
Max   :if(Total<=29+getbit (calendardata[m],n)) {
In   :  isend=truebreak;
  :  }
  :  total=total-29-getbit (calendardata[m],n);
  :  }
  :  ifbreak;
  :  }
A   :  cyear=1921 + m;
  :  cmonth=k-n+1;
  £  cday=total;
  :if(k==12) {
*   :  if(Cmonth==math.floor (calendardata[m]/0x10000) +1) {
  £ º  cmonth=1-cmonth;
  :  }
Si   :if(Cmonth>math.floor (calendardata[m]/0x10000) +1) {
  :  cmonth--;
  :  }
  £ º  }
  :  }
  59:
  :function getcdatestring () {
tmp=   :var "";
+   :if(cmonth<1) {
tmp+=   :  "(Leap)";
  :  Tmp+=monstring.charat (-cmonth-1);
  :  }else{
  :  Tmp+=monstring.charat (cMonth-1);
  :  }
tmp+=   :  "Month";
A   :  tmp+= (cday<11)?" Early ":((cday<20)? "Ten":((cday<30)? " 20": "30"));
  :if (cday%10!=0| | cday==10) {
  :  Tmp+=numstring.charat ((cDay-1)%10);
  :  }
  :return tmp;
A   :  }
  75:
  :function getlunarday (solaryear,solarmonth,solarday) {
  ://solaryear = solaryear<1900? ( 1900+solaryear): solaryear;
  :if(solaryear<1921 | | solaryear>2020) {
  :return"";
  :  }else{
  Bayi:  solarmonth = (parseint (solarmonth) >0)? (solarMonth-1): one;
  :  e2c (solaryear,solarmonth,solarday);
  :  return getcdatestring ();
  :  }
  :  }
  86:
  :var d=New Date ();
n   :var yy=d.getfullyear ();
  :var mm=d.getmonth () +1;
  :var dd=d.getdate ();
  £ ºvar ww=d.getday ();
Ss=parseint   :var (D.gettime ()/1000);
  :if (yy<100) yy="+yy";
  94:function showcal () {
Nongli   :var = Getlunarday (YY,MM,DD);
  :return Nongli;
  :  }
  98:/* Lunar set end*/

Call

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

Effect:

September 11 is the date of the lunar calendar day

Use JavaScript to get the lunar date for the current 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.