当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


VB.NET DateTime IsLeapYear()用法及代码示例

IsLeapYear() 方法用于检查指定年份是否为闰年。

用法:

Function IsLeapYear(ByVal year as Integer) as Boolean

参数:

  • year:指定年份。

返回值:如果指定年份是闰年,则返回 True,否则返回 False 值。

程序/源代码:

下面给出了演示 DateTime 类的 IsLeapYear() 方法的源代码。给定的程序已成功编译并执行。

'VB.NET program to demonstrate IsLeapYear() method of 
'DateTime class.

Imports System

Module Module1
    Sub Main()
        Dim ret As Boolean = False

        ret = DateTime.IsLeapYear(2024)
        If (ret = True) Then
            Console.WriteLine("Specified year is leap year")
        Else
            Console.WriteLine("Specified year is not leap year")
        End If
    End Sub
End Module

输出:

Specified year is leap year
Press any key to continue . . .

说明:

在上面的程序中,我们创建了一个包含 Main() 函数的模块 Module1。 Main() 函数是程序的入口点。

在 Main() 函数中,我们创建了一个用 False 初始化的布尔变量 ret。在这里,我们使用 DateTime 类的 IsLeapYear() 方法检查指定的年份是否为闰年,并在控制台屏幕上打印相应的消息。





相关用法


注:本文由纯净天空筛选整理自 VB.Net program to demonstrate the IsLeapYear() method of DateTime class。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。