VB编程:DateSerial通过闰月判断闰年
程序代码:
- Private Function MonthToLeapYear(ByVal Yea As Integer) As Boolean
- MonthToLeapYear = Day(DateSerial(Yea, 2, 29)) = 29
- End Function
-
- Private Sub Command1_Click()
- If Len(Text1.Text) <= 4 Then
- If MonthToLeapYear(Text1.Text) = True Then
- Print Text1.Text & "年是闰年"
- Else
- Print Text1.Text & "年是平年"
- End If
- Else
- Print "错误:请输入正确的年份!"
- End If
- End Sub
学习总结:
DateSerial返回包含指定的年、月、日的 Variant (Date)。
语法 DateSerial(year, month, day)