星期、干支、二十八宿计算公式
点击次数:54 次 发布日期:2008-11-09 08:37:45 作者:源代码网
|
源代码网推荐 星期=[5 A(实际天数)] mod 7 源代码网推荐 源代码网推荐 2. 干支计算公式 源代码网推荐 六十甲子干支序号,从1->59->0。 源代码网推荐 六十甲子干支序号=[23 A(实际天数)] mod 60 源代码网推荐 源代码网推荐 3. 二十八宿计算公式 源代码网推荐 二十八宿序号=[23 A(实际天数)] mod 28 源代码网推荐 源代码网推荐 4. 实际天数A的计算 源代码网推荐 A=B(基本天数) C(闰日天数) 源代码网推荐 B=(计算年-1)*365 (要计算到年的月日天数) 源代码网推荐 例:1984年2月1日的基本天数B=(1984-1)*365 (31 1)=723827(天), 源代码网推荐 其中,31是1月为31天,1为2月1日为1天。 源代码网推荐 公元308年8月28日的基本天数 源代码网推荐 B=(308-1)*365 (31 28 31 30 31 30 31 27)=112055 239=112294(天) 源代码网推荐 这里的(要计算到年的月日天数),用的是公历,月日天数的规则我好 源代码网推荐 象小学就学过了。哈哈…… 源代码网推荐 源代码网推荐 C=(计算年-1) div 4 -误差修正值 fixValue2 源代码网推荐 fixValue2为0或者1。常值为0,当年数为闰年(公历闰年法)之中的3月 源代码网推荐 1日之后的为1。 源代码网推荐 源代码网推荐 误差修正值推算: 源代码网推荐 公元元年1月1日至1582年10月14日为0。 源代码网推荐 1582年10月15日至1699年12月31日为10。 源代码网推荐 从1701年1月1日起每增加一个世纪累加1,但能被400除尽的世纪不累 源代码网推荐 加1。此方法推算即可。 源代码网推荐 --有一个问题,1700年这一年的修正值应为多少呢?算法中正好没有 源代码网推荐 讲到,但看来应该是10。 源代码网推荐 源代码网推荐 例1701年1月1日起误差值为11,而1801年1月1日起误差修正值为12, 源代码网推荐 而1901年1月1日起误差修正值为13, 源代码网推荐 但2001年误差修正值仍为13,因为2000年能被400整除,故不累加。而 源代码网推荐 2101年1月1日起误差修正值为14。 源代码网推荐 源代码网推荐 5. 实例:1998.3.15的星期、干支与二十八宿 源代码网推荐 B=(1998-1)*365 (31 28 15)=728979 源代码网推荐 C=(1998-1) div 4 - 13 0 = 486 源代码网推荐 A=B C=728979 486=729465 源代码网推荐 星期序号=(5 729465) mod 7=0,即为星期日 源代码网推荐 干支序号=(13 729465) mod 60=58,即为辛酉 源代码网推荐 二十八宿序号=(23 729465) mod 28=4,即为房 源代码网推荐 源代码网推荐 =================================================== 源代码网推荐 好可怕!还有一些其它公式……但好象有些参数不知道怎么得到: 源代码网推荐 源代码网推荐 二十四节交节日算法: 源代码网推荐 用已知年的交接时辰加上22个小时35分,超过24要减去24,分数足60 源代码网推荐 进1个小时,即得到8年后的各节交节时辰。 源代码网推荐 如2000年雨水交节时辰为16时22分,则2008年雨水交节时辰为14时52 源代码网推荐 分。 源代码网推荐 因为16时22分 22时35分=38时57分。38-24=14时。 源代码网推荐 谁知道公元元年到公元八年的交节日,这个算法就可以实现了。--好 源代码网推荐 象逆算法可以解决这个问题。谁试试? 源代码网推荐 源代码网推荐 农历闰月算法: 软件开发网 www.mscto.com 源代码网推荐 农历中,二十四节气(十二节气和十二中气)的中气落在月末的话,下 源代码网推荐 个月就没有中气。农历将这种有节(节气)无气(中气)的月份规定为闰 源代码网推荐 月。平均计算,19年有七个闰月。 源代码网推荐 但二十四个节气的十二节气和十二中气是怎么分的呢?我没有资料, 源代码网推荐 估记应该是一节气一中气这样交叉。 :( 源代码网推荐 源代码网推荐 unit CNYear; 源代码网推荐 源代码网推荐 interface 源代码网推荐 uses sysutils; 源代码网推荐 type TCNDate = Cardinal; 源代码网推荐 function DecodeGregToCNDate(dtGreg:TDateTime):TCNDate; 源代码网推荐 function 源代码网推荐 GetGregDateFromCN(cnYear,cnMonth,cnDay:word;bLeap:Boolean=Fal 源代码网推荐 se):TDateTime; 源代码网推荐 function GregDateToCNStr(dtGreg:TDateTime):String; 源代码网推荐 function isCNLeap(cnDate:TCNDate):boolean; 源代码网推荐 implementation 源代码网推荐 const cstDateOrg:Integer=32900; //公历1990-01-27的TDateTime表 源代码网推荐 示 对应农历1990-01-01 源代码网推荐 const cstCNYearOrg=1990; 源代码网推荐 const cstCNTable:array[cstCNYearOrg..cstCNYearOrg 60] of 源代码网推荐 WORD=( // unsigned 16-bit 源代码网推荐 24402, 3730, 3366, 13614, 2647, 35542, 858, 1749, //1997 源代码网推荐 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, //2037 源代码网推荐 1195, 21179, 1453, 2922, 11690, 3474, 32421, 3365, //2045 源代码网推荐 2645, 55901, 1206, 1461, 14038); //2050 源代码网推荐 //建表方法: 源代码网推荐 // 0101 111101010010 高四位是闰月位置,后12位表示大小月,大月30 源代码网推荐 天,小月29天, 源代码网推荐 //闰月一般算小月,但是有三个特例2017/06,2036/06,2047/05 源代码网推荐 //对于特例则高四位的闰月位置表示法中的最高为设置为1 特殊处理 源代码网推荐 用wLeapNormal变量 源代码网推荐 // //2017/06 28330->61098 2036/06 27947->60715 2047/05 源代码网推荐 23133->55901 源代码网推荐 源代码网推荐 //如果希望用汇编,这里有一条信息:农历不会滞后公历2个月. 源代码网推荐 //将公历转换为农历 源代码网推荐 //返回:12位年份 4位月份 5位日期 源代码网推荐 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(IncMonth(dtGreg,-1),wYear,wMonth,wDay); 源代码网推荐 if (iDayLeave < 0) or (iDayLeave > 22295 )then Exit; 源代码网推荐 //Raise Exception.Create("目前只能算1990-01-27以后的"); 源代码网推荐 //Raise Exception.Create("目前只能算2051-02-11以前的"); 源代码网推荐 for i:=Low(cstCNTable) to High(cstCNTable) do begin 源代码网推荐 wBigSmallDist := cstCNTable[i]; 源代码网推荐 wLeap := wBigSmallDist shr 12; 源代码网推荐 if wLeap > 12 then begin 源代码网推荐 wLeap := wLeap and 7; 源代码网推荐 wLeapShift := 1; 源代码网推荐 end else 源代码网推荐 wLeapShift := 0; 源代码网推荐 for j:=1 to 12 do begin 源代码网推荐 wCount:=(wBigSmallDist and 1) 29; 源代码网推荐 if j=wLeap then wCount := wCount - wLeapShift; 源代码网推荐 if iDayLeave < wCount then begin 源代码网推荐 Result := (i shl 9) (j shl 5) iDayLeave 1; 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 iDayLeave := iDayLeave - wCount; 源代码网推荐 if j=wLeap then begin 源代码网推荐 wCount:=29 wLeapShift; 源代码网推荐 if iDayLeave < wCount then begin 源代码网推荐 Result := (i shl 9) (j shl 5) iDayLeave 1 (1 shl 21); 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 iDayLeave := iDayLeave - wCount; 源代码网推荐 end; 源代码网推荐 wBigSmallDist := wBigSmallDist shr 1; 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 //返回值: 源代码网推荐 // 1位闰月标志 12位年份 4位月份 5位日期 (共22位) 源代码网推荐 end; 源代码网推荐 function isCNLeap(cnDate:TCNDate):boolean; 源代码网推荐 begin 源代码网推荐 result := (cnDate and $200000) <> 0; 源代码网推荐 end; 源代码网推荐 function 源代码网推荐 GetGregDateFromCN(cnYear,cnMonth,cnDay:word;bLeap:Boolean=Fal 源代码网推荐 se):TDateTime; 源代码网推荐 var 源代码网推荐 i,j:integer; 源代码网推荐 DayCount:integer; 源代码网推荐 wBigSmallDist,wLeap,wLeapShift:WORD; 源代码网推荐 begin 源代码网推荐 // 0101 010010101111 高四位是闰月位置,后12位表示大小月,大月30 源代码网推荐 天,小月29天, 源代码网推荐 DayCount := 0; 源代码网推荐 if (cnYear < 1990) or (cnYear >2050) then begin 源代码网推荐 Result := 0; 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 for i:= cstCNYearOrg to cnYear-1 do begin 源代码网推荐 wBigSmallDist := cstCNTable[i]; 源代码网推荐 if (wBIgSmallDist and $F000) <> 0 then DayCount := DayCount 源代码网推荐 29; 源代码网推荐 DayCount := DayCount 12 * 29; 源代码网推荐 for j:= 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; //大月在闰月. 源代码网推荐 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 //是要闰月的吗? 源代码网推荐 DayCount := DayCount 30 - wLeapShift; 源代码网推荐 result := cstDateOrg DayCount cnDay - 1; 源代码网推荐 end; 源代码网推荐 源代码网推荐 //将日期显示成农历字符串. 源代码网推荐 function GregDateToCNStr(dtGreg:TDateTime):String; 源代码网推荐 const hzNumber:array[0..10] of string=("零","一","二","三"," 源代码网推荐 四","五","六","七","八","九","十"); 源代码网推荐 function ConvertYMD(Number:Word;YMD:Word):string; 源代码网推荐 var 源代码网推荐 wTmp:word; 源代码网推荐 begin 源代码网推荐 result := ""; 源代码网推荐 if YMD = 1 then begin //年份 源代码网推荐 while Number > 0 do begin 源代码网推荐 result := hzNumber[Number Mod 10] result; 源代码网推荐 Number := Number DIV 10; 源代码网推荐 end; 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 if Number<=10 then begin //可只用1位 源代码网推荐 if YMD = 2 then //月份 源代码网推荐 result := hzNumber[Number] 源代码网推荐 else //天 源代码网推荐 result := "初" hzNumber[Number]; 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 wTmp := Number Mod 10; //个位 源代码网推荐 if wTmp <> 0 then result := hzNumber[wTmp]; 源代码网推荐 wTmp := Number Div 10; //十位 源代码网推荐 result:="十" 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 := "输入越界"; 源代码网推荐 Exit; 源代码网推荐 end; 源代码网推荐 cnDay := cnDate and $1F; 源代码网推荐 cnMonth := (cnDate shr 5) and $F; 源代码网推荐 cnYear := (cnDate shr 9) and $FFF; 源代码网推荐 //测试第22位,为1表示闰月 源代码网推荐 if isCNLeap(cnDate) then strLeap:="(闰)" else strLeap := ""; 源代码网推荐 result := "农历" ConvertYMD(cnYear,1) "年" 源代码网推荐 ConvertYMD(cnMonth,2) "月" 源代码网推荐 strLeap ConvertYMD(cnDay,3) ; 源代码网推荐 end; 源代码网推荐 end. 源代码网推荐 源代码网供稿. |
