How to get the lunar program code in JavaScript

Source: Internet
Author: User
Tags getdate

Get Lunar calendar

The days of the lunar calendar are a variable, sometimes 29 days, sometimes 30 days.

The first day of the lunar calendar is the day when the moon is All black.

The Lunar New Year is determined by the 24 solar terms, which are determined by the sun's angle. The first solar term of the lunar calendar is called rain, fixed in the sun's angle of 330 degrees of the day. The remaining 23 solar terms are set at the angle of the sun every 15 degrees each day. The following table lists the names and definitions of 24 solar terms:

Call Angle Gregorian Calendar date period

Spring 315 February 4

Rain 330 February 19 29.8 days

Insects 345 March 6

Vernal Equinox 0 March 21 30.2 days

Qingming 15 April 5

Rain 30 April 20 30.7 days

Summer 45 May 6

Summer Full 60 May 21 31.2 Days

Grain 75 June 6

Summer Solstice 90 June 22 31.4 days

Slight Heat 105 July 7

Great Heat 120 July 23 31.4 Days

Autumn 135 August 8

Chushu 150 August 23 31.1 days

White Dew 165 September 8

Autumnal Equinox 180 September 23 30.7 days

Dew 195 October 8

Frost 210 October 24 30.1 Days

Winter 225 November 8

Snow 240 November 22 29.7 days

Snow 255 December 7

Winter Solstice 270 December 22 29.5 days

Xiaohan 285 January 6

Dahan 300 January 20 29.5 days

24 Solar terms in 12 are the main solar terms: Rain, vernal equinox, rainfall, summer full, the summer solstice, great heat, Chushu, Autumnal Equinox, Frost, snow, Winter solstice, Dahan.

The lunar calendar year differs greatly from the astronomical year. The Lunar New Year has 12 lunar months, 353,354, or 355 days, about 11 days younger than astronomy. In order to synchronize with the astronomical year, every three lunar calendar around the year, must set a leap year. Leap year has 13 months, the added month is called the leap.

The names of the lunar calendar 12 months are: First month, February, March, April, May, June, July, August, September, October, winter months, month.

The Lunar leap year leap month's determination is more difficult, the leap month lunar calendar algorithm has two:

• One: The winter solstice must fall on the lunar winter months. If not, the month will be added one months before the leap year.
• Two: If it is a leap year, winter months the first month excluding the main solar term. The name of the January leap month before use.
The Lunar New Year is a 60-year cycle, and the name of the year is arranged by a word of 10 heavenly stems and one of 12 branches of the earthly branch.

10 Days of work:

• A, B, C, Ding, E, Ren, Geng, Xin, Yi, gui.
12 Earthly Branches are:

* Son, Ugly, my colleagues, Mao, Chen, the afternoon, no, Shen, unitary, Xu, Hai.
• 12 Earthly Branches have 12 animals of the Zodiac and their corresponding:
Rats, cows, tigers, rabbits, dragons, snakes, horses, sheep, monkeys, chickens, dogs, pigs.
According to historical records, the Lunar New Year has gone through 78 cycles. This year, the Gregorian calendar 2010, is the 79th cycle of the 28th year, that is, the No. 4707 year of the lunar calendar

The code is as follows Copy Code

<script type= "Text/javascript" >
<!--
var now=new Date ();
-->
</script>
<script language=javascript>
<!--
var lunarinfo=new Array (0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
0X06CA0,0X0B550,0X15355,0X04DA0,0X0A5D0,0X14573,0X052D0,0X0A9A8,0X0E950,0X06AA0,
0X0AEA6,0X0AB50,0X04B60,0X0AAE4,0X0A570,0X05260,0X0F263,0X0D950,0X05B57,0X056A0,
0X096D0,0X04DD5,0X04AD0,0X0A4D0,0X0D4D4,0X0D250,0X0D558,0X0B540,0X0B5A0,0X195A6,
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
0X04AF5,0X04970,0X064B0,0X074A3,0X0EA50,0X06B58,0X055C0,0X0AB60,0X096D5,0X092E0,
0X0C960,0X0D954,0X0D4A0,0X0DA50,0X07552,0X056A0,0X0ABB7,0X025D0,0X092D0,0X0CAB5,
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
0X05AA0,0X076A3,0X096D0,0X04BD7,0X04AD0,0X0A4D0,0X1D0B6,0X0D250,0X0D520,0X0DD45,
0X0B5A0,0X056D0,0X055B2,0X049B0,0X0A577,0X0A4B0,0X0AA50,0X1B255,0X06D20,0X0ADA0);

= = The total number of days returned to the lunar year Y
function Lyeardays (y) {
var i, sum = 348
For (i=0x8000 i>0x8; i>>=1) sum = = (lunarinfo[y-1900] & i)? 1:0
Return (Sum+leapdays (y))
}
= = The number of days to return the lunar calendar y-year leap
function Leapdays (y) {
if (Leapmonth (y)) return ((lunarinfo[y-1900] & 0x10000)? 30:29)
else return (0)
}
= = To return to the lunar calendar y year 1-12, no leap back to 0
function Leapmonth (y) {return (lunarinfo[y-1900] & 0xf)}
====================================== returns the total number of days of the lunar calendar Y-year m-months
function Monthdays (y,m) {return (lunarinfo[y-1900] & (0x10000>>m)) 30:29)}
= = Calculate the lunar calendar, incoming Date object, return the Lunar date object
The object property has. Year month. Isleap. yearcyl. daycyl. moncyl
function Lunar (objdate) {
var i, leap=0, temp=0;
var basedate = new Date (1900,0,31);
var offset = (objdate-basedate)/86400000;
This.daycyl = offset + 40;
this.moncyl = 14;
For (i=1900 i<2050 && offset>0; i++) {
temp = Lyeardays (i);
offset = temp;
This.moncyl + 12;
}
if (offset<0) {
Offset + temp;
i--;
This.moncyl-= 12;
}
This.year = i;
this.yearcyl = i-1864;
Leap = Leapmonth (i); Which month does the leap
This.isleap = False
For (I=1 i<13 && offset>0; i++) {
Leap
if (leap>0 && i== (leap+1) && this.isleap==false)
{I. THIS.ISLEAP = true; temp = Leapdays (this.year);}
Else
{temp = Monthdays (this.year, i);}
Lift Leap Month
if (this.isleap==true && i== (leap+1)) This.isleap = False
Offset = Temp
if (This.isleap = false) This.moncyl + +
}
if (offset==0 && leap>0 && i==leap+1)
if (THIS.ISLEAP)
{this.isleap = false;}
Else
{this.isleap = true;--this.moncyl;}
if (offset<0) {offset = temp;--this.moncyl;
This.month = i
This.day = offset + 1
}
function Cday (m,d) {
var nstr1 = new Array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine ', ' ten ');
var nstr2 = new Array (' early ', ' ten ', ' 20 ', ' 30 ', ');
var s;
if (m>10) {s = ' ten ' +nstr1[m-10]} else {s = nstr1[m]} s + = ' month '
if (s== "December") s = "Lunar";
if (s== "January") s = "First month";
Switch (d) {
Case 10:s + = ' decade '; Break
Case 20:s + = ' 20 '; Break
Case 30:s + = ' 30 '; Break
Default:s + + Nstr2[math.floor (D/10)]; s + + nstr1[d%10];
}
return (s);
}
function Solarday2 () {
var sdobj = new Date (Now.getfullyear (), Now.getmonth (), now.getdate ());
var ldobj = new Lunar (sdobj);
var cl = ';
Lunar New Year BB ' + (cld[d].isleap? ') Leap ': ' +cld[d].lmonth+ ' month ' +cld[d].lday+ ' Day
var tt = Cday (ldobj.month,ldobj.day);
document.write (Now.getfullyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Japanese Lunar Calendar" +tt+ ");
}
Solarday2 ();
-->
</script>

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.