Sender: hifi (~ zzz), the letter area: Program Title: Re: Question and Lunar Relationship! Sending station: Commander Terracotta BBS Station (Sun Jul 11 23:26:28 1999) : I have never seen: I have to say: [In the masterpiece of Zixim (Zhei Simon):] Give you a Delphi routine: (I also copy, algorithm, please analyze it yourself .) unit cNYear; interface uses sysutils; type TCNDate = Cardinal; function DecodeGregToCNDate (dtGreg: TDateTime): TCNDate; function GetGregDateFromCN (cnYear, cnMonth, cnDay: word; bLeap: Boolean = False): TDateTime; function GregDateToCNStr (dtGreg: TDateTime : String; function iscnleap (cndate: tcndate): boolean; importation constdeorg: integer = 32900; // 公e = 1990-01-27 TDATETIME indicates that corresponds to Lunar calendar 1990-01-01 Const cstcnyearorg = 1990; const cstractcntable: Array [cstcnyearorg..cstcnyearorg 60] of word = (// unsigned 16-bit 24402, 3730, 3366, 13614, 2647, 35542, 858, 1749, //997 23401, 1865, 1683, 19099, 1323, 2651, 10926 , 1386, // 2005 32213, 2980, 2889, 23891, 2709, 1325, 17757, 2741, // 2013 39850, 1490, 3493, 61098, 3402, 3221, 19102, 1366, // 2021 2773, 10970, 1746, 26469, 1829, 1611, 22103, 3243, // 2029 1370, 13678, 2902, 48978, 2898, 2853, 60715, 2635, 1453, 2922, 11690, 3474, 32421, 3365, // 2045 2645, 55901, 12 06, 1461, 14038); // 2050 // Construction form method: // 0101 111101010010 High four bits are the moon position, the latter 12 points indicate the size of the month, the month is 30 days, the month is 29 days, // Take the month Month, but there are three special examples 2017/06,2036/06, 2047/05 // For the high four-digit leap month position indication method is set to 1 special treatment WLEAPNORMAL variable /// 2017/06 28330 -> 61098 2036/06 27947-> 60715 2047/05 23133-> 55901 // If you want to use compilation, here there is a message: Lunar calendar will not lag the gift calendar 2 months. // Convert the Queen calendar to Lunaru // Return: 12 Year month 4 5 bit bit date function DecodeGregToCNDate (dtGreg: TDateTime): TCNDate; var iDayLeave: Integer; wYear, wMonth, wDay: WORD; i, j: integer; wBigSmallDist, wLeap, wCount, wLeapShift: WORD; label OK; begin result: = 0; idayleave: =
Trunc (DTGREG) - CSTDATEORG; DECODEDATE (IDAYLEAVE <0) or (iDayleave> 22295) THEN EXIT; // raise exception.create (' Countd in 1990-01-27); // raise exception.create ('currently only 2051-02-11 "); for i: = low (cstcntable) to high (cstcntable) Do Begin WbigsmallDist: = CSTCNTABLE [I]; WLEAP: = WbigsmallDist SHR 12; if WLEAP> 12 THEN WLIN WLEAP: = WLEAP AND 7; WLSE WLEAPSHIFT: = 0; for J: = 1 To 12 do begin wcount: = (wbigsmalldist and 1) 29; if j = WLLAP THEN WCOUNT: = Wcount - WLEAPSHIFT; IDAYLEAVE
1 to 12 do begin DayCount: = DayCount wBigSmallDist and 1; wBigSmallDist: = wBigSmallDist shr 1; end; end; wBigSmallDist: = cstCNTable [cnYear]; wLeap: = wBigSmallDist shr 12; if wLeap> 12 then begin wLeap: = wLeap And 7; wleapshift: = 1; // Dalgo is in the month. END ELSE WLEAPSHIFT: = 0; for j: = 1 to cnmonth-1 Do Begin Daycount: = daycount (wbigsmallDist and 1) 29; if j = WLEAP then DayCount: = DayCount 29; wBigSmallDist: = wBigSmallDist shr 1; end; if bLeap and (cnMonth = wLeap) then // leap month is to do DayCount: = DayCount 30 - wLeapShift; result:? = cstDateOrg DayCount CNDAY - 1; END; // Display the date as a lunar string. Function GregDateTocnstr (DTGREG: TDATETIME): String; const hznumber: array [0..10] of string = ('zero', 'one ",' ',' Three ',' four ',' eight ',' nine ',' 10 '); Function Convertymd (Number: Word; YMD: Word): String; Var WTMP: Word; Begin Result: = '; if YMD = 1 Then Begin // While While Number> 0 Do Begin Result: = Hznumber [Number Mod 10] Result; Number: = Number Div 10; End; End; End; ; if Number <= 10 Then Begin // can only use 1 bit if YMD = 2 TH EN / / Month Result: = Hznumber [Number] Else // Sky Result: = 'First' Hznumber [Number]; EXIT; END; WTMP: = Number MOD 10; // Fence IF WTMP <> 0 Then Result: = hznumber [wtmp]; WTMP: = Number Div 10; // Ten Result: = 'Ten' Result; if WTMP> 1 Then Result: = Hznumber [wtmp] Result; End; Var CNYear, CNMONTH, CNDAY: Word; cndate: tcndate; strleap: string; begin cndate: = decodegregtocndate (DTGREG); if cndate = 0 THEN BEGIN RESULT: = 'Enter the Crossing'; EXIT; End; CNDAY: =