公农历转换vb类 clsdate
网上流传很多计算公农历的源代码,很多,但是居然没有vb的,晕,
所以。。。。。
用法:
以l开始的方法均为阴历,以s开始的方法均为公历
基本的两个初使函数:
linitdate:用农历年月日初使化日期对象
sinitdate: 用公历年月日初使化日期对象
其它的方法看下面的一小段代码吧
示例代码
private sub command1_click()
dim t as clsdate
dim y as long
dim m as long
dim d as long
dim st as single
dim et as single
dim da as date
dim j as long
dim ret as long
set t = new clsdate
't.sinitdate 1900, 1, 1
t.linitdate 2047, 5, 12, false '农历2047年5月12日,非闰月
debug.print t.lyear
if t.isleap = false then
debug.print t.lmonth
else
debug.print " 闰 " & t.lmonth
end if
debug.print t.cdaystr(t.lday) '农历日期中文大写
debug.print t.ganzhi(t.lyear) '求干支
debug.print t.yearattribute(t.lyear) '农历年的属相
debug.print t.syear ' 公历年
debug.print t.smonth ' 公历月
debug.print t.sday ' 公历日
debug.print t.sweekday '公历星期
debug.print t.era(t.syear)' 公历纪元
debug.print t.constellation(t.smonth, t.sday) ' 星座
debug.print "week:" & t.wholiday ' 按第几个星期几计算的假日
debug.print "solar" & t.sholiday ' 按公历计算的假日
debug.print "lunar" & t.lholiday ' 按阴历计算的假日
debug.print t.lsolarterm ' 计算节气
'以下为速度测试,很快吧。
st = timer
with t
for y = 1900 to 2049
for m = 1 to 12
for d = 1 to 28
.linitdate y, m, d, false
next
next
next
end with
't.printf
et = timer
debug.print et - st
set t = nothing
end sub
‘///////////////////////////////////////////////////////////////////////////////
'
' 以下为源代码部分,如果你需要在你的程序中使用,请在你写一封e-mail给我,至少让我知道有人
' 还在用它。
'
' e-mail: lxs@xtcz.net
' zhenghesoft@hotmail.com
' qq: 248241571
' bluedog 即日
’
option explicit
' ///////////////////////////////////////////////////////////////////////////////
' // //
' // //
' // 说明:本模块仅能用于1900.1.31日起至 2049.12.31日止的数据转换,否则会出错。 //
' // 或者农力1900.1.1日起至2049.12.7日止 //