有没有计算一个月天数的方法?
答案 0 :(得分:17)
是:
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。
答案 1 :(得分:0)
http://authors.aspalliance.com/aspxtreme/sys/DateTimeClassDaysInMonth.aspx
Public Shared Function DaysInMonth ( _
ByVal year As Integer, _
ByVal month As Integer _
} As Integer
答案 2 :(得分:0)
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
您当然可以更改输出日期的方式,以便将其格式化为您的意愿。
答案 3 :(得分:0)
获取当月的天数
Dim CurrentMonthDays As Int16 = DateTime.DaysInMonth(DateTime.Now.Year,DateTime.Now.Month)
答案 4 :(得分:-1)
使用数组:[31,28,31,30,31,30,31,31,30,31,30,31] 如果(年份mod 400 = 0)或((年份mod 4 = 0)而不是(年份mod 100 = 0),则添加1到2月
答案 5 :(得分:-2)
您有两个简单的解决方案:
5546>>m&1|30^(m==2)*2+(m==2&&y%4==0)))
或
(62648012>>m*2&3)+28+(m==2&&y%4==0)))
其中m是月份,y是年份。
这个解决方案在下面是一个数组,但数组是用魔术数字掩盖的。