加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB.NET根据年月获得总周数

发布时间:2020-12-16 22:37:32 所属栏目:大数据 来源:网络整理
导读: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
    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根据年月获得总周数

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读