前端之家收集整理的这篇文章主要介绍了
VB.NET根据年月获得总周数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub Button7_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button7.Click
MsgBox("总周数:" & GetTotalWeeks(Me.monthid.Text))
End Sub
Private Function GetTotalWeeks(ByVal monthid As String) As Integer
Dim y,m As String
y = monthid.Substring(0,4)
m = monthid.Substring(4)
Dim totalweeks As Integer
Dim FirstDayOfMonth As Date = New DateTime(y,m,1)
Dim LastDayOfMonth As Date = New DateTime(y,Date.DaysInMonth(y,m))
Dim d As Date = FirstDayOfMonth
Dim ed(0) As Date
Dim j As Int16
For i As Int16 = 0 To Date.DaysInMonth(y,m) - 1
If d.DayOfWeek = DayOfWeek.Saturday Then
ReDim Preserve ed(j)
ed(j) = d
j = j + 1
End If
d = d.AddDays(1)
Next
For i As Int16 = 0 To ed.Length - 1
MsgBox(ed(i))
Next
totalweeks = ed.Length
If ed(ed.Length - 1) <= LastDayOfMonth Then
totalweeks = totalweeks + 1
End If
Return totalweeks
End Function
VB.NET根据年月获得总周数
原文链接:https://www.f2er.com/vb/260291.html