本文整理匯總了VB.NET中System.DateTime.DaysInMonth方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DateTime.DaysInMonth方法的具體用法?VB.NET DateTime.DaysInMonth怎麽用?VB.NET DateTime.DaysInMonth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.DaysInMonth方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Class Example
Public Shared Sub Main()
Const July As Integer = 7
Const Feb As Integer = 2
Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)
Console.WriteLine(daysInJuly)
' daysInFeb gets 28 because the year 1998 was not a leap year.
Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)
Console.WriteLine(daysInFeb)
' daysInFebLeap gets 29 because the year 1996 was a leap year.
Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)
Console.WriteLine(daysInFebLeap)
End Sub
End Class
輸出:
31 28 29
示例2: Example
' 導入命名空間
Imports System.Globalization
Module Example
Public Sub Main()
Dim years() As Integer = { 2012, 2014 }
Dim dtfi As DateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo
Console.WriteLine("Days in the Month for the {0} culture " +
"using the {1} calendar",
CultureInfo.CurrentCulture.Name,
dtfi.Calendar.GetType.Name.Replace("Calendar", ""))
Console.WriteLine()
Console.WriteLine("{0,-10}{1,-15}{2,4}", "Year", "Month", "Days")
Console.WriteLine()
For Each [year] As Integer In years
For ctr As Integer = 0 To dtfi.MonthNames.Length - 1
If String.IsNullOrEmpty(dtfi.MonthNames(ctr)) Then
Continue For
End If
Console.WriteLine("{0,-10}{1,-15}{2,4}", [year],
dtfi.MonthNames(ctr),
DateTime.DaysInMonth([year], ctr + 1))
Next
Console.WriteLine()
Next
End Sub
End Module
輸出:
Days in the Month for the en-US culture using the Gregorian calendar Year Month Days 2012 January 31 2012 February 29 2012 March 31 2012 April 30 2012 May 31 2012 June 30 2012 July 31 2012 August 31 2012 September 30 2012 October 31 2012 November 30 2012 December 31 2014 January 31 2014 February 28 2014 March 31 2014 April 30 2014 May 31 2014 June 30 2014 July 31 2014 August 31 2014 September 30 2014 October 31 2014 November 30 2014 December 31