在交货日期排除周末

时间:2015-09-30 20:14:38

标签: vb.net datetime

我有一个获得ETA的代码(预计到达时间),但我希望它排除周末。如果过去下午2:30,我也可以更改ETA。

代码:

    Dim ETA1 As Date = Date.Today.AddDays(1)
    Dim ETA2 As Date = Date.Today.AddDays(2)
    Dim ETA3 As Date = Date.Today.AddDays(3)

    Dim day As String = Format(Today, "dddd")
    Dim time As Date
    Dim CurrHour As Integer
    Dim CurrMinute As Integer
    time = DateTime.Now
    CurrHour = time.Hour
    CurrMinute = time.Minute

    If StoreBox.Text Like "25*" Then
        MicroLabel.Visible = True

        If CurrHour >= 2 AndAlso CurrMinute >= 30 Then
            ETABox.Text = ETA2
        Else
            ETABox.Text = ETA1
        End If

    Else
        MicroLabel.Visible = False

        If CurrHour >= 2 AndAlso CurrMinute >= 30 Then
            ETABox.Text = ETA2
        Else
            ETABox.Text = ETA1
        End If

    End If

1 个答案:

答案 0 :(得分:1)

DateTime是一种非常灵活的类型,可让您轻松执行许多与日期/时间相关的操作。您不需要执行类似字符串的分析(您的代码正在做什么)。

例如,要处理两个请求的功能,只需执行以下操作:

Dim curTime As DateTime = Now
Dim goAhead As Boolean = True

If curTime.DayOfWeek = DayOfWeek.Saturday OrElse curTime.DayOfWeek = DayOfWeek.Sunday Then
    goAhead = False
ElseIf curTime > New DateTime(curTime.Year, curTime.Month, curTime.Day, 14, 30, 0) Then
    goAhead = False
End If

If goAhead Then
    'Weekday before 2:30 PM
End If
相关问题