1

今天你会如何在 VB.net 中约会。然后找到下一周的星期一或星期五的日期。如果今天是星期四并且我正在寻找下一个星期五,那么我想要明天的日期吗?

4

2 回答 2

2

您可以使用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)

你会得到明天的约会

于 2012-10-06T00:05:26.773 回答
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
于 2019-01-08T15:46:31.677 回答