0

我有以下代码

        Dim time As Date
    Dim currentHour As Integer
    Dim currentMinute As Integer

    time = DateTime.Now
    currentHour = time.Hour
    currentMinute = time.Minute

    If currentHour > 10 AndAlso currentMinute > 8 Then
        Response.Redirect("holdingpage.aspx")

    Else
        'do nothing
    End If

基本上,如果当前时间在上午 10.08 之后,我想重定向到另一个页面,但没有任何反应。

4

2 回答 2

1

好吧,如果是 11:00,您的代码将失败。

使用任一

If currentHour > 10 OrElse (currentHour = 10 AndAlso currentMinute > 8) Then

甚至更好

If Date.Now.TimeOfDay > New TimeSpan(10, 8, 0) Then
于 2013-07-12T09:21:20.197 回答
-1

对它进行排序,我基本上添加了 = 作为它在英国的 10.30,所以它在不等于的情况下失败了。

代码现在

        Dim time As Date
    Dim currentHour As Integer
    Dim currentMinute As Integer

    time = DateTime.Now
    currentHour = time.Hour
    currentMinute = time.Minute

    If currentHour >= 10 And currentMinute >= 8 Then
        Response.Redirect("HoldingPage.aspx")

    Else
        'do nothing
    End If
于 2013-07-12T09:31:21.297 回答