當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。