打印本文 打印本文  关闭窗口 关闭窗口  
判断一个年份是否为闰年
作者:佚名  文章来源:不详  点击数  更新时间:2008/4/18 14:48:39  文章录入:杜斌  责任编辑:杜斌

下面的例子采用非API的方法来判断一个年份是否为闰年。
闰年判断方法:能够被4或100或400整除的年份为闰年。

在一个窗体中放入一个CommandButton,然后放入下述代码

Option Explicit

Private Sub Command1_Click()

Print 2000,
Print IsLeapYearA(2000),
Print IsLeapYearB(2000)

Print 1999,
Print IsLeapYearA(1999),
Print IsLeapYearB(1999)

Print 1998,
Print IsLeapYearA(1998),
Print IsLeapYearB(1998)

Print 1997,
Print IsLeapYearA(1997),
Print IsLeapYearB(1997)

Print 1996,
Print IsLeapYearA(1996),
Print IsLeapYearB(1996)

End Sub

Function IsLeapYearA(ByVal yr As Integer) As Boolean
If ((yr Mod 4) = 0) Then 
IsLeapYearA = ((yr Mod 100) > 0) Or ((yr Mod 400) = 0)
End If
End Function

Public Function IsLeapYearB(ByVal yr As Integer) As Boolean

IsLeapYearB = Day(DateSerial(yr, 2, 29)) = 29

End Function
 
打印本文 打印本文  关闭窗口 关闭窗口