每月的一周,一年中的一年,一年

时间:2018-01-05 11:31:29

标签: vb.net datetime dayofweek weekday

我想检查一周中的月份,一年中的一个月和一年,但我每周都有问题 这是代码:

Public Class BMW
    Public Shared Function GetWeekNumber() As Integer
        Threading.Thread.Sleep(2000)

        Dim span As TimeSpan = DateTime.Now - New Date(DateTime.Now.Year, 1, 1)
        Return (CInt(span.TotalDays) \ 7) + 1

        If span.TotalDays = 1 Then

            SendKeys.Send("{1}")
            MsgBox(span.TotalDays)

        Else
            MsgBox("chybi1")
end if
end function

2 个答案:

答案 0 :(得分:0)

Google是你的朋友:

Private Function GetWeekNumber() As Integer
    Dim span As TimeSpan = DateTime.Now - New Date(DateTime.Now.Year, 1, 1)
    Return (CInt(span.TotalDays) \ 7) + 1
End Function

我甚至不确定这是你在找什么......

答案 1 :(得分:-1)

公共共享函数GetWeekNumber(ByVal datum As Date)As Integer

    Dim weeknumber = Math.Floor(datum.Day / 7 + +1)

    SendKeys.Send(weeknumber)
    Return weeknumber

End Function