Conversion of the yang to the lunar calendar

zhaozj2021-02-08  208

Seeing a lot of people on 9CBS asking questions about the lunar calendar, I checked, the document center has not been related articles, and there is a piece of information, where to forget, now put the full text, I hope to help everyone. .

- 90. Computer Language, C (90: 90/1237) ------------------------------------ ------- 90-C -

MSG: # 404 [407]

From: sunshine lin 90: 2010/633 thu 29 aug 96 22:05

TO: Steven Shui Sun 01 Sep 96 05:03

SUBJ: National calendar

-------------------------------------------------- ------------------------------

.Msgid: 90: 2010 / 633.0 32264c56

.Pid: BWRA 3.02 [Eval]

.Tid: GE 1.11

replied as below...

SS> Does anyone know the algorithm of "National Convention Lunar"?

SS> I hope to know the seniors to enlighten me.

The rude algorithm of the lunar calendar is quite complicated, and most of them are completed by the table.

The following advances are found on the Internet.

In addition, I also found another step is written by the mainland, and I can react it.

Also count eight words. If you are interested, write to me, I will put it again !!

-------------------------------------------------- ------------------

Sender: smhwang @ phoenix (full automatic wolf), letter area: programming

Title: --- Vehicles and Lunar Conversion Forms ---

Sending station: Jiaotong University, Phoenix, Phoenix Information Station (WED JUL 26 01:51:17 1995)

Transmission station: Phoenix

Origin: kscg-ts5.kscg.gov.tw

This franchise welcomes all versions of the stations, and there is no need to agree. If you are interested in the calendar, welcome to discuss.

/ *

Wan Xiaoming 1995, 7, 25

Prototype: int Calconv (STRUCT Convdate *);

Struct convdate

{

Int source; == 0 Enter the date in the record,! = 0 Enter is a lunar calendar

Int Solaryear; Western Medicine Output or Enter

Int Solarmonth; Vehcoon

Int solardate;

INT Lunaryear; Output or Enter Lunar New Year

Int lunarmonth; lunar month

Int Lunardate; Lunar New Year

Int weekday; this day is the day of the week (0 == Sunday, 1 == Monday, ...)

Int kan; day dry (0 == A, 1 == B, ..., 9 ==)

Int Chih; this day of the day (0 ==), 1 == Ugly, ..., 11 == Hai)

}

When the call is required to set the value of the Souce, if it is 0, it is a recorded lunar calendar. Otherwise, it will turn the Lunar Calendar. Then depend

Enter the annual day of the contraman or lunar calendar to set the monkey or lunar calendar. The year and month after the conversion will be filled in the structure (agriculture

Calendar or Western calendar, and the day is a day, and the sky is branched.

If the reputation of the function is 0, it is not an error, and 1 is an incorrect error, and 2 is incorrectly entered.

3 For the input date error.

Input weeks must be in 1937 - 2031

Enter the lunar calendar year must be in 1936 - 2030

If you need to expand, add lunarcal [] * /

#define first year 1936 / * The first year in lunarcal [] * /

Struct convdate

{

Int source;

Int Solaryear;

Int solarmonth;

Int solardate;

Int Lunaryear;

Int lunarmonth;

Int Lunardate;

Int weekday;

Int kan;

Int chih;

}

Struct Taglunarcal

{

Int basedays; / * to the Western 1st to the number of days in the first day of the lunar calendar * /

INTITERCALATION; / * Take the month. 0 == There is no leap in this year * /

Int baseweekday; / * This year, the Western Day is 1 * /

INT basekanchih; / * This year, the sanctuary of January 1 is reduced by 1 * /

Int monthdays [13]; / * This lunar month size, 0 == Xiaoyue (29th), 1 == Dali (30th) * /

}

Struct taglunarcal lunarcal [] = {

{23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0), / * 1936 * /

{41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1),

{30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1),

{49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1),

{38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1}, / * 1940 * /

{26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0),

{45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),

{35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1),

{24, 4, 5, 59, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1}, / * 1944 * /

{43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1),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, 1, 0, 1, 0, 1, 0, 1, 0, 1},

{31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0),

{21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1),

{40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1}, / * 2024 * /

{28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0),

{47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1),

{36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1),

{25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, / * 2028 * /

{43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1),

{32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0),

{22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0})

#define Lastyear (Firstyear Sizeof (Lunarcal) / Sizeof (Struct Taglunarcal) -1)

/ * Number of days per month * /

INT Solarcal [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/ * The number of days per month, the number of days and leap years * /

Int SolarDays [2] [14] = {

{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396},

{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397}};

/ * Ask if this west calendar year is a leap year, return 0 is the year, 1 is a leap year * / int getleap (int year)

{

IF (Year% 400 == 0)

Return 1;

Else IF (Year% 100 == 0)

Return 0;

Else IF (Year% 4 == 0)

Return 1;

Else

Return 0;

}

/ * Survey Lunar Conversion * /

INT Calconv (Struct Convdate * CD)

{

INT LEAP, D, SM, Y, IM, L1, L2, ACC, I, LM, KC;

IF (CD-> Source == 0) / * Solar * /

{

IF (CD-> Solaryear <= firstyear || CD-> Solaryear> Lastyear)

Return 1;

SM = CD-> Solarmonth - 1;

IF (SM <0 || SM> 11)

Return 2;

Leap = getleap (CD-> Solaryear);

IF (SM == 1)

D = leap 28;

Else

D = Solarcal [SM];

IF (CD-> Solardate <1 || CD-> Solardate> D)

Return 3;

Y = CD-> Solaryear - firstyear;

ACC = SolarDays [Leap] [SM] CD-> Solardate;

CD-> weekday = (ACC Lunarcal [Y] .baseweekday)% 7;

Kc = ACC Lunarcal [Y] .Basekanchih;

CD-> kan = kc% 10;

CD-> CHIH = KC% 12;

IF (ACC <= Lunarcal [Y] .BaseDays)

{

Y--

CD-> Lunaryear = CD-> Solaryear - 1;

Leap = Getleap (CD-> Lunaryear);

SM = 12;

ACC = SolarDays [Leap] [SM] CD-> Solardate;

}

Else

CD-> Lunaryear = CD-> Solaryear;

L1 = lunarcal [y] .basedays;

For (i = 0; i <13; i )

{

L2 = L1 Lunarcal [Y] .MONTHDAYS [i] 29;

IF (ACC <= L2)

Break;

L1 = L2;

}

CD-> lunarmonth = i 1;

CD-> Lunardate = ACC - L1;

IM = Lunarcal [Y] .intercalation;

IF (IM! = 0 && CD-> Lunarmonth> IM)

{

CD-> lunarmonth -;

IF (cd-> lunarmonth == iM)

CD-> lunarmonth = -im;

}

IF (CD-> Lunarmonth> 12)

CD-> Lunarmonth - = 12;

}

ELSE / * LUNAR * /

{

IF (CD-> Lunaryear Lunaryear> = lastyear)

Return 1;

Y = CD-> Lunaryear - firstyear;

IM = Lunarcal [Y] .intercalation;

LM = CD-> Lunarmonth;

IF (lm <0)

{

IF (lm! = -im)

Return 2;

}

ELSE IF (LM <1 || LM> 12)

Return 2;

IF (IM! = 0)

{

IF (lm> IM)

LM ;

ELSE IF (lm == -im)

LM = IM 1;

}

LM -;

IF (CD-> Lunardate> Lunarcal [Y] .MONTHDAYS [LM] 29)

Return 3;

ACC = Lunarcal [Y] .BaseDays;

For (i = 0; i

ACC = Lunarcal [Y] .MONTHDAYS [I] 29;

ACC = CD-> Lunardate;

Leap = Getleap (CD-> Lunaryear);

For (i = 13; i> = 0; I -)

IF (ACC> SolarDays [leap] [i])

Break;

CD-> Solardate = ACC - SolarDays [leap] [i];

IF (i <= 11)

{

CD-> Solaryear = CD-> LunaryEar;

CD-> Solarmonth = i 1;

}

Else

{

CD-> Solaryear = CD-> LunaryEar 1;

CD-> Solarmonth = I - 11;

}

Leap = getleap (CD-> Solaryear);

Y = CD-> Solaryear - firstyear;

ACC = SolarDays [Leap] [CD-> Solarmonth-1] CD-> Solardate;

CD-> weekday = (ACC Lunarcal [Y] .baseweekday)% 7;

Kc = ACC Lunarcal [Y] .Basekanchih;

CD-> kan = kc% 10;

CD-> CHIH = KC% 12;

}

Return 0;

}

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

New Post(0)