如何判断vb.net中特定月份dates 10 and 25
是否在Saturday or Sunday
上?
If dates is on Saturday then
msgbox(cut off move to friday)
elseif dates is on Sunday then
msgbox(cut off move to monday)
答案 0 :(得分:2)
只需检查DateTime结构的DayOfWeek属性。
If dates.DayOfWeek = DayOfWeek.Saturday then
msgbox(cut off move to friday)
elseif dates.DayOfWeek = DayOfWeek.Sunday then
msgbox(cut off move to monday)
答案 1 :(得分:1)
正如Brendan Green指出的那样,只需比较日期时间的DayOfWeek财产:
Sub Main
Dim dateToCompare As New DateTime(2014, 5, 10)
Dim cutoff As DateTime
If dateToCompare .DayOfWeek = DayOfWeek.Saturday Then
cutoff = dateToCompare .AddDays(-1)
Else
If dateToCompare .DayOfWeek = DayOfWeek.Sunday Then
cutoff = dateToCompare .AddDays(1)
Else
cutoff = dateToCompare
End If
End If
Console.WriteLine("The cutoff date is {0}", cutoff)
End Sub