今天在VB.net中如何约会?然后找到下周的星期一或星期五的日期。如果今天是星期四,我正在寻找下周五,那么我希望明天的约会?
答案 0 :(得分:1)
您可以使用DayOfWeek枚举来查找:
Private Function GetNextDate(day As DayOfWeek) As DateTime
Dim now As DateTime = DateTime.Today
Dim today As Integer = CInt(now.DayOfWeek)
Dim find As Integer = CInt(day)
Dim delta As Integer = find - today
If delta > 0 Then
Return now.AddDays(delta)
Else
Return now.AddDays(7 - delta)
End If
End Function
使用您的示例,如果您致电:
Dim date = GetNextDate(DayOfWeek.Friday)
你明天的约会
答案 1 :(得分:0)
Private Function NextMonday() As String
Dim Tdate = DateTime.Now.AddDays(1)
Do While Tdate.DayOfWeek <> DayOfWeek.Monday
Tdate = Tdate.AddDays(1)
Loop
Return Tdate.ToShortDateString()
End Function