JavaScript gets the current date's lunar date code _javascript tips

Source: Internet
Author: User
Tags getdate

JavaScript code

/* Set the Lunar date */var calendardata=new Array (100);

var madd=new Array (12);

var numstring= "1,234,567,890";

var monstring= "is 234,567,890 winter wax";

var cyear,cmonth,cday,thedate; The 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,0x526,0x31d26,0xd95, 0X70B55,0X56A,0X96D,0X5095D,0X4AD,0XA4D, 0X41A4D,0XD25,0X81AA5,0XB54,0XB6A,0X612DA,0X95B,0X49B,0X41497,0XA4B,0XA164B, 0x6a5,0x6d4,0x615b4,0xab6,0x 957,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 () {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]&LT;0XFFF)? 11:12;

for (n=k;n>=0;n--) {if (Total<=29+getbit (calendardata[m],n)) {isend=true;

} 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= ""; Ifcmonth<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

Copy Code code 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.