求阳历2006-11-1日对应的阴历#NAME?
求阴历2006年正月初一对应的阳历#NAME?
阳历1975年5月6日出生,今年阴历生日时对应的阳历日期#NAME?
阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期#NAME?
Dim d As
Dim Month
'1901-210
LunarCal
startyear
d = &H100
ng = ng M
d = &H80
mdata = I
ng = ng M
d = &H20
LunarData
LunarData
d = &H100
i = 1
Do
Lunar
mdata
If d
d = d
i = i
Loop
If LunarD En
Fu luna
'Part = 0
Dim a As
l_year =
a = Lunar
sp_date =
If sp_dat
l_yea
a = L
sp_da
End If
l_day = S
l_month =
IS_lunar_
y = a.Mon
Do While
l_day
If l_
If IS
y
Else
l
y
End I
Loop
l_day = l
lunar = l
If IS_lun
lunar = C En
Fu sola
'IS_lunar
Dim a As
Lunar_dat
s_year =
For Each
If C
Next
a = Lunar
sp_date =
If Lunar_
x = Lunar
tm = Luna
For i = 1
x = x
If i
x
End I
Next
s_date =
solar = s En
Fu luna
If Inquir
Inqui
lunar
If CD
End If
lunarbirt En
Fu sola
If Inquir
Inqui
solar
If CD
End If
solarbirt En
函数作用:阴阳历转换和阴阳历生日
'    说明:适用于1901-2100年间
示例:=lunar("2006-11-1")
=solar("2006-1-1")    求阴历2006年正月初一对应的阳历
=lunarbirth("1975-5-6")  阴历生日:阳历1975年5月6日出生,今年阴历生日时对应的阳历日期            =solarbirth("1975-5-6")  阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期'>>>>>>>>>>>>####
Type ConvDataA
leapmonth As Integer
Month(1 To 13) As Integer
sp_month As Integer 'Solar month of Spring Festival
sp_day As Integer 'Solar day  of Spring Festival
End Type
Private Function LunarData(q_year) As ConvDataA
Dim d As Long
Dim Month(1 To 13) As Integer
'1901-2100
LunarCal = Array(&H4AE53, &HA5748, &H5526BD, &HD2650, &HD9544, &H46AAB9, &H56A4D, &H9AD42,              &H6A4DBE, &HA4D52, &HD2546, &H5D52BA, &HB544E, &HD6A43, &H296D37, &H95B4B, &H74              &HA4B48, &H5B25BC, &H6A550, &H6D445, &H4ADAB8, &H2B64D, &H95742, &H2497B7, &H49              &HD4A51, &HEA546, &H56D4BA, &H5AD4E, &H2
B644, &H393738, &H92E4B, &H7C96BF, &HC9              &H6DA53B, &HB554F, &H56A45, &H4AADB9, &H25D4D, &H92D42, &H2C95B6, &HA954A, &H7B                &HB5546, &H555ABB, &H4DA4E, &HA5B43, &H352BB8, &H52B4C, &H8A953F, &HE9552, &H6A                &HAB54F, &H4B645, &H4A5739, &HA574D, &H52642, &H3E9335, &HD9549, &H75AABE, &H56              &H54AEBB, &H4AD4F, &HA4D43, &H4D26B7, &HD254B, &H8D52BF, &HB5452, &HB6A47, &H69              &H49B45, &H4A4BB9, &HA4B4D, &HAB25C2, &H6A554, &H6D449, &H6ADA3D, &HAB651, &H93              &H4974F, &H64B44, &H36A537, &HEA54A, &H86B2BF, &H5AC53, &HAB647, &H5936BC, &H92              &H4D4AB8, &HD4A4C, &HDA541, &H25AA36, &H56A49, &H7AADBD, &H25D52, &H92D47, &H5C                &HB4A43, &H4B5537, &HAD54A, &H955ABF, &H4BA53, &HA5B48, &H652BBC, &H52B50, &HA9              &H6AA4C, &HAD541, &H24DAB6, &H4B64A, &H69573D, &HA4E51, &HD2646, &H5E933A, &HD5              &H36B537, &H96D4B, &HB4AEBF, &H4AD53, &HA4D48, &H6D25BC, &HD254F, &HD5244, &H5D                &H56D41, &H24ADB6, &H49B4A, &H7A4BBE, &HA4B51, &HAA546, &H5B52BA, &H6D24E, &HAD                &H9374B, &H8497C1, &H49753, &H64B48, &H66A53C, &HEA54F, &H6B244, &H4AB638, &HAA                &H3C9735, &HC9649, &H7D4ABD, &HD4A51, &HDA545, &H55AABA, &H56A4E, &HA6D43, &H45              &H8A95BF, &HA9553, &HB4A47, &H6B553B, &HAD54F, &H55A45, &H4A5D38, &HA5B4C, &H52              &H69349, &H7729BD, &H6AA51, &HAD546, &H54DABA, &H
4B64E, &HA5743, &H452738, &HD2              &HD5252, &HDAA47, &H66B53B, &H56D4F, &H4AE45, &H4A4EB9, &HA4D4C, &HD1541, &H2D9    startyear = 1901
ng = LunarCal(q_year - startyear)
d = &H100000
LunarData.leapmonth = Int(ng / d)
ng = ng Mod d
d = &H80
mdata = Int(ng / d)
ng = ng Mod d
d = &H20
LunarData.sp_month = Int(ng / d)
LunarData.sp_day = ng Mod d
d = &H1000
i = 1
Do
LunarData.Month(i) = 29 + Int(mdata / d)
mdata = mdata Mod d
If d = 1 Then Exit Do
d = d / 2
i = i + 1
Loop
If LunarData.leapmonth = 0 Then LunarData.Month(i) = 0
End Function
Function lunar(Solar_date As Date, Optional Part As Integer = 0) As String 'Part = 0, all; Part = 1, lunar year; Part = 2, lunar month; Part = 3, lunar day Dim a As ConvDataA
l_year = Year(Solar_date)
a = LunarData(l_year)
sp_date = DateSerial(l_year, a.sp_month, a.sp_day)
If sp_date > Solar_date Then
l_year = l_year - 1
a = LunarData(l_year)
sp_date = DateSerial(l_year, a.sp_month, a.sp_day)
End If
l_day = Solar_date - sp_date
l_month = 1
IS_lunar_leapmonth = False
y = a.Month(l_month)
Do While l_day >= y
l_day = l_day - y
If l_month = a.leapmonth Then IS_lunar_leapmonth = (Not IS_lunar_leapmonth)
If IS_lunar_leapmonth Then
y = a.Month(13)
Else
l_month = l_month + 1
y = a.Month(l_month)
End If
Loop
l_day = l_day + 1
lunar = l_year & "-" & l_month & "-" & l_day
If IS_lunar_leapmonth Then lunar = lunar & "-L"
lunar = Choose(Part + 1, lunar, l_year, l_month, l_day)
End Function
Function solar(Lunar_date, Optional IS_lunar_leapmonth As Integer = 0) As String
'IS_lunar_leapmonth = 0, No leap month; IS_lunar_leapmonth = 1, is leap month
Dim a As ConvDataA
Lunar_date = Split(Lunar_date, "-")
s_year = Lunar_date(0)
For Each C In Lunar_date
If C = "L" Then IS_lunar_leapmonth = 1
Next
mid函数提取年月日a = LunarData(s_year)
sp_date = DateSerial(s_year, a.sp_month, a.sp_day)
If Lunar_date(1) <> a.leapmonth Then IS_lunar_leapmonth = 0
x = Lunar_date(2)
tm = Lunar_date(1) + IS_lunar_leapmonth - 1
For i = 1 To tm
x = x + a.Month(i)
If i = a.leapmonth And IS_lunar_leapmonth = 0 Then
x = x + a.Month(13)
End If
Next
s_date = sp_date + x - 1
solar = s_date
End Function
Function lunarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String If Inquire_year = 0 Then
Inquire_year = Left(lunar(Now), 4)
lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10)) If CDate(lunarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 End If
lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10))
End Function
Function solarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String If Inquire_year = 0 Then
Inquire_year = Year(Now)
solarbirth = DateSerial(Inquire_year, Month(Solar_birthday), Day(Solar_birthday)) If CDate(solarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 End If
solarbirth = DateSerial(Inquire_year, Month(Solar_birthday), Day(Solar_birthday)) End Function

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论