Есть ли какой-либо метод для вычисления количества дней за месяц?
Да:
Const July As Integer = 7
Const Feb As Integer = 2
' daysInJuly gets 31. '
Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)
' daysInFeb gets 28 because the year 1998 was not a leap year. '
Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)
' daysInFebLeap gets 29 because the year 1996 was a leap year. '
Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)
Кредит принадлежит MSDN .
http://authors.aspalliance.com/aspxtreme/sys/DateTimeClassDaysInMonth.aspx
Public Shared Function DaysInMonth ( _
ByVal year As Integer, _
ByVal month As Integer _
} As Integer
Dim d As New DateTime(2010, 4, 1)
Dim month As Integer = d.Month
While d.Month = month
Console.WriteLine(d.[Date])
d = d.AddDays(1)
End While
Конечно, вы можете изменить способ вывода даты, чтобы отформатировать ее по своему усмотрению.
Используйте массив: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] {{1 }} Добавьте единицу к февралю, если (модификация года 400 = 0) или ((модификация года 4 = 0), а не (модификация года 100 = 0))