原想从立春开始往后每个节气按365.2422/24=15.218425的间隔推算,结果发现有的日期不准确,如是以1997年的各节气时间为标准来推算,发现日期基本准确,但仍然不能精确到秒,能精确到小时就很不错了,实在不行用查表完成吧。
Function getSolar(inYear As Integer) As String
'根据给出的年份返回该年份所有节气准确时间,精确到秒,从立春开始用逗号间隔开
Const y_s = 31556925.9747
'一年的总秒数
Const bs = "1997-01-05 15:24:28"
'1997年小寒的准确时间
Const jq = "小寒,大寒,立春,雨水,惊蛰,春分,清明,谷雨,立夏,小满,芒种,夏至,小暑,大暑,立秋,处暑,白露,秋分,寒露,霜降,立冬,小雪,大雪,冬至"
Const jqjg = "0,21198.05,42457.483,63807.02,85299.65,106950.2,128791.8,150818.35,173034.967,195413.42,217928.05,240535.467,263184.92,285830.97,308411.833,330894.72,353224.35,375390.983,397360.7,419150.283,440750.167,462203.083,483520.4,504401.42"
Dim i As Integer, j As Integer, c As Double, d1 As Date, m() As String, n() As String, b(23) As Date, a As String
m = Split(jq, ","): n = Split(jqjg, ",")
c = (inYear - 1997) * y_s
'获取给出的年份和基础年份间隔的总秒数
d1 = DateAdd("s", c, bs)
'获取该年份的小寒具体日期,精确到秒
If UBound(m) <> 23 And UBound(n) <> 23 Then Exit Function
For i = 0 To 23
c = Val(n(i)) * 60
b(i) = DateAdd("s", c, d1)
Next
a = ""
For i = 0 To 23
j = i + 2
If j > 23 Then j = j - 24
a = a & inYear & "年" & m(j) & ":" & b(j) & ","
Next
a = Left(a, Len(a) - 1)
getSolar = a
End Function
Private Sub Form_Click()
Dim y As Integer, a As String, b() As String, i As Integer
y = InputBox("请输入查询年份:")
If y < 1900 Then y = 1997
a = getSolar(y)
b = Split(a, ",")
Me.Cls
For i = 0 To 23
Print b(i)
Next
End Sub
Private Sub Form_Load()
Me.Show
Me.AutoRedraw = True
Form_Click
End Sub