Realize the date conversion of the Queen calendar with JScript

zhaozj2021-02-16  45

This article introduces the method of the Queen to the Lunchak Date Transformation with the Characterization Method, gives a practical JScript script. Acceptable Guest Calendar Date range from 2001-1 to 2050-12-31.

// Array LunardaySofmont stores the number of monthly days of the lunar calendar 2001 to 2050

// The lunar calendar can only be 29 or 30 days, with 12 (or 13) binary positions in a year, from high to low, corresponding position is 1 for 30 days, otherwise 29 days

Var lunardaysofmonth = new arch

(

0xD4A8, 0X5AA8, 0X56A0, 0XAAD8, 0X25D0, 0X92D0, 0XC958, 0XA950, / / ​​2001-2010

0xB4A0, 0xB550, 0xB550, 0x55A8, 0X4BA0, 0XA5B0, 0X52B8, 0X52B0, 0XA930, 0X74A8, / / ​​2011-2020

0x6aa0, 0xAd50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xE930, 0xD530, 0x5aa0, // 2021-2030

0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, // 2031-2040

0x56D0, 0x4AD8, 0X49B0, 0XA4B8, 0XA4B0, 0XAA50, 0XB528, 0X6D20, 0XADA0, 0X55B0 / / 2041-2050

);

// A number of LunarleApyear stores the month of the lunar calendar 2001 to 2050, if it is 0, from high to low, each word is two years

Var lunarleApyear = New Array

(

0x40, 0x02, 0x07, 0x00, 0x50, // 2001-2010

0x04, 0x09, 0x00, 0x60, 0x04, // 2011-2020

0x00, 0x20, 0x60, 0x05, 0x00, // 2021-2030

0x30, 0xB0, 0x06, 0x00, 0x50, // 2031-2040

0x02, 0x07, 0x00, 0x50, 0x03 // 2041-2050

);

/ / Return the lunar month of the lunar calendar, if it is not returned 0

Function Getleapmonth (iLunaryear)

{

Var Leap = lunarleApyear [(iLunaryear - 2001) >> 1];

RETURN ((iLunaryear - 2001) & 1) == 0)? (Leap >> 4): (Leap & 0x0f);

}

// Return the number of days of the lunar calendar ilunaryer year, the result is a long integer

// If ilunarmonth is not a month, high character is 0, the low word is the number of days of the month

// If ilunarmonth is a month, high words are the number of days after a month, the low words are the days before the month.

Function Lunarmonthdays (Ilunaryear, Ilunarmont)

{

Var high;

Var low;

Var bit;

HIGH = 0;

Low = 29;

Bit = 16 - ilunarmonth;

IF ((iLunarmonth> Getleapmonth) && (GetleapMonth (iLunaryear)> 0)) Bit--

IF (Lunardaysofmonth [ILunaryear - 2001] & (1 << Bit))> 0) Low ; IF (ilunarmonth == Getleapmonth (iLunaryear))

{

HIGH = (Lunardaysofmonth [ILunaryear - 2001] & (1 << (bit-1)))> 0) 30: 29;

}

Return Low (High << 16);

}

// Return the total number of days of lunar calendar iLunaryear

Function LunaryEardAys (Ilunaryear)

{

Var days;

VAR TMP;

Days = 0;

FOR (var i = 1; i <= 12; i )

{

TMP = lunarmonthdays (ilunaryear, i);

Days = days ((TMP >> 16) & 0xfffff); // Take high

Days = days (TMP & 0xFFFF); // Take a low position

}

Return day;

}

// Format the lunar calendar iLunaryear in the annual manuscript

Function Formatlunaryear (iLunaryear)

{

Var sztext1 = new string ("methyl isthyl propenochuracy);

Var sztext2 = new string ("Ziqiu Yuchen Niu Nou);

Var stryear;

Stryear = sztext1.substr (iLunaryear - 4)% 10, 1);

Stryear = strYear sztext2.substr ((iLunaryear - 4)% 12, 1);

Return strsyear "year";

}

// Stylize the lunar calendar in IlunarmonTh month into a string representation

Function Formatlunarmonth (Ilunarmont)

{

Var Sztext = New String ("Zhengsi 23456789);

Var strmonth;

IF (ilunarmonth <= 10)

{

Strmonth = sztext.substr (Ilunarmonth - 1, 1);

}

Else IF (ilunarmonth == 11) strMonth = "11";

Else strmonth = "twelve";

Return strMonth "Month";

}

// Format the lunar calendar olunarday to the string of lunar calendar

Function Formatlunarday (ILunarday)

{

Var Sztext1 = New String ("First Times Third");

Var sztext2 = new string ("One Two Thirty-four Fifth or 56789);

Var strday;

IF ((ilunarday! = 20) && (ilunarday! = 30))))

{

STRDAY = sztext1.substr ((ilunarday - 1) / 10, 1) sztext2.substr ((ilunarday - 1)% 10, 1);

}

Else IF (ilunarday! = 20)

{

StRDAY = sztext1.substr (Ilunarday / 10, 1) "Ten";

Else

{

STRDAY = "twenty";

}

Return strday;

}

// convert the date of the reputation to the Lunar New Year, return to the string of lunar calendar

Function Getlunardatestring (Solardate)

{

VAR TMP;

Var ilunaryear;

Var ilunarmonth;

Var ilunarday;

Var Leap = false;

VAR minMilli = 1000 * 60;

Var HRMILLI = Minmilli * 60;

VAR DYMILLI = HRMILLI * 24;

// From January 1, 2001, the number of days after a given question calendar has passed

// 11323 is the number of days between January 1, 1970 to January 1, 2001, because Date is from January 1, 1970 as a starting point

Var ispandays = math.round (solardate.gettime () / DYMILLI) - 11323;

// Ceremony January 24, 2001 for the first month of the first month of 2001, 23 days

IF (ISPANDAYS <23)

{

Iyear = 2000;

Ilunarmonth = 12;

ilunarday = ispandays 7;

}

Else

{

// From the first month of the lunar calendar 2001

ISPANDAYS = ISPANDAYS - 23;

Ilunaryear = 2001;

Ilunarmonth = 1;

ilunarday = 1;

// Calculate the Lunar Year

TMP = LunaryEardAys (iLunaryear);

While (ispandays> = TMP)

{

ISPANDAYS - = TMP;

Ilunaryear ;

TMP = LunaryEardAys (iLunaryear);

}

// calculate the lunar month

TMP = lunarmonthdays (ilunaryear, ilunarmonth) & 0xfff; // Take a low word

While (ispandays> = TMP)

{

ISPANDAYS - = TMP;

IF (ilunarmonth == getleapmonth (ilunaryear)) // This month is the month

{

TMP = lunarmonthdays (ilunaryear, ilunarmonth >> 16; // Take high words

IF (ISPANDAYS

{

Leap = (TMP> 0)? True: false; // Later month after the month?

Break;

}

ISPANDAYS = ISPANDAYS - TMP;

}

Ilunarmonth ;

TMP = lunarmonthdays (ilunaryear, ilunarmonth) & 0xfff; // Take a low word

}

// Calculate the Lunar Day

Ilunarday = ispandays;

}

RETURN FORMATLUNARYAREAR (ILUNARYEAR) (Leap? "": "") FormatLunarmonth (ilunarmonth) FormatLunarday (ILunarday);

}

The calling method is as follows:

Var Today = new date (); // Today is 2004-3-5VAR str = getLunardatestring (Today);

The result is "Epssive Epssive Epssive".

Take another two examples:

Var Date1 = New Date (2008, 9, 1); // 2008-10-1

Var Date2 = New Date (2050, 4, 18); // 2050-5-18

Var str1 = getLunardatestring (date1);

Var str2 = getlunardatestring (date2);

The results were "the third year of September", respectively, and "Hesheng Birth".

Note In Date, the range of months is 0-11.

[related resources]

Kernel Studio: www.kernelstudio.com

Release Date: 2004-03-05

转载请注明原文地址:https://www.9cbs.com/read-23658.html

New Post(0)