全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3606
推到 Plurk!
推到 Facebook!

求星期公式

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-26 16:08:07 IP:61.64.xxx.xxx 未訂閱
此為轉貼資料 求星期公式 -------------------------------------------------------------------------------- 1. 求星期公式 星期=[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時。 誰知道西元元年到西元八年的交節日,這個演算法就可以實現了。--好 象逆演算法可以解決這個問題。誰試試? 農曆閏月演算法: 農曆中,二十四節氣(十二節氣和十二中氣)的中氣落在月末的話,下 個月就沒有中氣。農曆將這種有節(節氣)無氣(中氣)的月份規定?閏 月。平均計算,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. ********************************************************* 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind to make knowledge together! 希望能大家敞開心胸,將知識寶庫結合一起
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
系統時間:2024-05-12 2:08:19
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!