DaysInMonth() 方法用於獲取指定年份的指定月份中的天數。
用法:
Function DaysInMonth (ByVal year as Integer, ByVal month as Integer) as Integer
參數:
- Year:指定年份
- Date2:指定月份
返回值:它返回指定年份的指定月份中的天數。
程序/源代碼:
下麵給出了演示 DateTime 類的 DaysInMonth() 方法的源代碼。給定的程序已成功編譯並執行。
'VB.NET program to demonstrate DaysInMonth() method of
'DateTime class.
Imports System
Module Module1
Sub Main()
Dim days As Integer = 0
days = DateTime.DaysInMonth(2021, 2)
Console.WriteLine("Number of Days in Feb 2021 are:{0}", days)
End Sub
End Module
輸出:
Number of Days in Feb 2021 are:28 Press any key to continue . . .
說明:
在上麵的程序中,我們創建了一個包含 Main() 函數的模塊 Module1。 Main() 函數是程序的入口點。
在 Main() 函數中,我們創建了一個初始化為 0 的整數變量 days,在這裏,我們得到了 2021 年 2 月的天數,即 28。之後,我們在控製台屏幕上打印天數。
相關用法
- VB.NET DateTime FromBinary()用法及代碼示例
- VB.NET DateTime ToBinary()用法及代碼示例
- VB.NET DateTime Equals()用法及代碼示例
- VB.NET DateTime IsLeapYear()用法及代碼示例
- VB.NET DateTime Compare()用法及代碼示例
- VB.NET LTrim()用法及代碼示例
- VB.NET CLng()用法及代碼示例
- VB.NET RTrim()用法及代碼示例
- VB.NET GetChar()用法及代碼示例
- VB.NET Array Reverse()用法及代碼示例
- VB.NET Array Resize()用法及代碼示例
- VB.NET CInt()用法及代碼示例
- VB.NET CULng()用法及代碼示例
- VB.NET CDbl()用法及代碼示例
- VB.NET LCase()用法及代碼示例
- VB.NET Array ConstrainedCopy()用法及代碼示例
- VB.NET Array Clear()用法及代碼示例
- VB.NET Array LastIndexOf()用法及代碼示例
- VB.NET String Join()用法及代碼示例
- VB.NET String IsNullorWhitSpace()用法及代碼示例
注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the DaysInMonth() method of DateTime class。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。