日期转换...(100分)

  • 主题发起人 Another_eYes
  • 开始时间
A

Another_eYes

Unregistered / Unconfirmed
GUEST, unregistred user!
公历<-->农历...
 

去Delphi开发室
http://www.zg169.net/~randolph/cncalc.zip

CnCalcdar(带源码)

一个能显示农历的日历元件,有效时间区间为1901年至2050年,农历数据来源于UCDOS
6.0中UCT.COM,共600字节。附赠一个UCDOS下打印带农历的日历的程序及其C++源码。


32bit深度历险也有一个:
http://vcl.vclxx.com
全部免费控件->中文环境
REXCAL.ZIP

国历与农历合而为一的月历 ,并提供农历与西洋历的转换单元,此版不
需要 Delphi 3.0 的中文应用组件,(附源码),作者:彭宏杰。

我自己也写了一个(数据全部手工输入),你如果还不满意以上,
可以e-mail我
 
两个东东我都看过,兄弟,那是一个对照表,按表的方式显示
公/农历,所以不能在1901年至2050年之外!

一定有一个通用的算法,可以准确的转换公/农历,而不是对
照表!Another_eYes and jiangtao,我老早就在找这么个东东了。 :(
 
农历计算没有通用方法!
 
农历也是推算出来的, 只是不知道其算法罢了
 
注:以下代码不是本人的, 是从网上来的.

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

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

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=False):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

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.

 
http://www.netease.com/~bozhi/
 
我以前曾经问过万年历程序的作者,他告诉我《十万个为什么》里面有介绍,
另外,天文台出版的历法书中也有介绍,可惜我手头一时找不到,不知哪位
大侠能够找到,我也出分奖励,:)
 
如果能够将十天干,十二地支也能够算出, 推算个生辰八字,流年什么的就方便了.
 
to 会长:如果有一定寄给我,我出50
 
我手头可有不少算命软件哟!
就是没有源码。:(
 
洋为中用啊!!!

中学为体,西学为用!!!!

算命的玩意都有人要搞,不太好吧???
 
我总觉得你想搞算命软件,否则用不着穷根问底。
 
Hi, tqz
我有科学算命的源程序,不知是否需要?(可否用分来“买”呢?300$)
 
科学算命?你怎么相信这种东西?
 
delphi fan2也只是把那个对照表帖出来而已. 没四年一个润月这是大家都知道的,
要推算出润月在那个月的算法还是没有. 那位兄弟化点时间到图书馆去查询一下.
 
>没四年一个润月这是大家都知道的
会长老师,农历好像是十七年四闰吧?
好像那个月是闰月是通过看一个月中的三天是否满足条件决定的(从中央一台看的)。
如果一个月中没有满足条件的三天,就向后推,所以闰月最多到闰八月。
 
置润月的规则好象是:如果某个月出现3个节气(就是茶叶蛋
说的"满足条件的三天"),就在这个月前(或后,不太清除)置
润.如果某年有满足置润条件的月,一定置润,这一年就叫润
年,而不是先确定是否润年再计算润月的位置.

农历的润年很频繁的决不至于4年一润或17年4润这么稀疏.
具体多密记不得了.大概比隔一年一润少(或多,不确定)一点.

农历月计算的原理:月亮绕地球一周为一个农历月.由于月亮
的周期是29.5天多一点,所以农历月有大小之分,大月30,小月
29.如果有月亮周期的准确数据,可以推算每个月是大还是小.

24节气原理:地球绕太阳转15度为一节气.由于地球轨道是椭
圆,每个节气间的时间是不等的.有每个节气间的精确时间,就
可以准确地置节气.

结合月计算原理和节气计算原理,再加上参考的起点(没有起点
就没有日历,公历也有参考起点的),就可以用准确的天文数据计
算出农历.但是,由于天文数据时常有波动和变化,又由于推算时
间长了之后积累误差很容易超过一天,此时历法就不能用了.一
般来说农历每几十年要校对一下参考起点和天文参数.从公历的
置润之复杂可见一斑.
 
如果现在的程序可以解决这个问题,天文台号要来干吗?
目前不同天文台的计算结果都有争执!
 
顶部