Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Datetime 具有检测日期/时间的经典ASP_Datetime_Asp Classic - Fatal编程技术网

Datetime 具有检测日期/时间的经典ASP

Datetime 具有检测日期/时间的经典ASP,datetime,asp-classic,Datetime,Asp Classic,我有下面的代码来检测用户点击网页的日期和时间 dim time_hour dim time_min dim day_name dim shouldShowNormal dim showMsg time_hour = Hour(Now()) time_min = Minute(Now()) day_name = LCase(WeekdayName(Weekday(Now()))) shouldShowNormal = true if (day_nam

我有下面的代码来检测用户点击网页的日期和时间

dim time_hour
dim time_min
dim day_name
dim shouldShowNormal
dim showMsg

    time_hour = Hour(Now())
    time_min  = Minute(Now())
    day_name  = LCase(WeekdayName(Weekday(Now())))
    shouldShowNormal = true

    if (day_name = "thursday") then
        'Its Thursday so check the time
        if (Cint(time_hour) = 19 AND Cint(time_min) <= 59) then
            'Its between 19:00p-19:30p [7:00pm - 8:00pm]
            shouldShowNormal = false
        else
            'nothing is effected
            shouldShowNormal = true
        end if
    elseif (day_name = "wednesday") then
        'Its Wednesday so check the time
        if (Cint(time_hour) = 20 AND Cint(time_min) >= 30) then
            if (Cint(time_hour) = 21 AND Cint(time_min) <= 30) then
                'It's between 20:30p-21:30p [8:30pm - 9:30pm]
                shouldShowNormal = true
            else
                'nothing is effected
                shouldShowNormal = false
            end if
        else
            'nothing is effected
            shouldShowNormal = true
        end if
    elseif (day_name = "saturday") then
        'Its Saturday so check the time
        if (Cint(time_hour) = 17 AND Cint(time_min) <= 59) then
            'It's between 17:00p-18:00p [5:00pm - 6:00pm]
            shouldShowNormal = false
        else
            'nothing is effected
            shouldShowNormal = true
        end if
    else
        'nothing is effected
        shouldShowNormal = true
    end if

这可以根据需要工作,但我想知道是否有一种更简单、代码更少的方法来做同样的事情?

您可以提取一个函数来检查当前时间是否在指定的时间之间,然后只需要检查当天+开放时间

因为从您使用的函数来看,分钟数不能超过59,所以一个简单的函数就可以了(它实际上检查前两个参数是否超出范围,如果不超出范围,则返回true)。与上面的if语句相比,最后一次检查相对简单

function IsBetween (curHour, curMinute, minHour, minMinute, maxHour, maxMinute)
    if curHour < minHour or curHour > maxHour or (curHour = minHour and curMinute < minMinute) or (curHour = maxHour and curMinute > maxMinute) then
        IsBetween = false
        Exit Function
    end if
    IsBetween = true
end function

dim time_hour
dim time_min
dim day_name
dim showNormal

day_name  = LCase(WeekdayName(Weekday(Now())))
time_hour = Hour(Now())
time_min  = Minute(Now())
' default to false, and only set it to true if we are in opening hours '
showNormal = false

If (day_name = "wednesday" And IsBetween(time_hour, time_min, 19, 0, 20, 0)) Or _
   (day_name = "thursday" And IsBetween(time_hour, time_min, 20, 30, 21, 30)) Or _
   (day_name = "saturday" And IsBetween(time_hour, time_min, 17, 0, 18, 0)) Then
    ' we are open :) '
    showNormal = true
End If
函数介于(curHour、curMinute、minHour、minminminute、maxHour、maxMinute)之间
如果curHourmaxHour或(curHour=minHour和curMinutemaxMinute),则
IsBetween=false
退出功能
如果结束
IsBetween=true
端函数
暗时间
暗时间
黯淡的日子
暗显正常
day_name=LCase(WeekdayName(Weekday(Now()))
时间\小时=小时(现在()
时间\分钟=分钟(现在()
'默认为false,仅当我们在营业时间时才将其设置为true'
showNormal=false
如果(day_name=“星期三”和IsBetween(time_hour,time_min,19,0,20,0))或_
(day_name=“星期四”和IsBetween(time_hour,time_min,20,30,21,30))或_
(day_name=“saturday”和IsBetween(time_hour,time_min,17,0,18,0))然后
“我们营业:)”
showNormal=true
如果结束
顺便问一下,你确定你周三的支票有效吗?你似乎在某个特定的时间检查小时数是否为20,然后如果小时数为21,这两种情况都不可能是真的:)

函数IsNormalTime(dDateTime)
“//默认值为true
IsNormalTime=True
“//检查星期几并设置开始/结束时间
昏昏欲睡
选择案例工作日(dDateTime)
案例4'//星期三
IsNormalTime=False
tStart=cDate(“20:30:00”)
倾向=cDate(“21:30:00”)
案例5'//星期四
tStart=cDate(“19:00:00”)
倾向=cDate(“20:00:00”)
案例7'//星期六
tStart=cdate(“17:00:00”)
倾向=cDate(“18:00:00”)
其他情况
退出功能
结束选择
“//仅获取时间部分
dim dTimeOnly:dTimeOnly=dDateTime-FIX(dDateTime)
“//对照开始/结束时间检查时间
选择case true
案例dTimeOnly=tEnd
退出功能
结束选择
“//反转正常时间
IsNormalTime=不是IsNormalTime
端函数

您可以构建一个日期+时间字符串,然后进行选择。星期三对吗?它给出了与前几天相反的结果。我已经对它进行了编码,以便在下面的回答中给出完全相同的结果,但我怀疑有一个bug。
function IsBetween (curHour, curMinute, minHour, minMinute, maxHour, maxMinute)
    if curHour < minHour or curHour > maxHour or (curHour = minHour and curMinute < minMinute) or (curHour = maxHour and curMinute > maxMinute) then
        IsBetween = false
        Exit Function
    end if
    IsBetween = true
end function

dim time_hour
dim time_min
dim day_name
dim showNormal

day_name  = LCase(WeekdayName(Weekday(Now())))
time_hour = Hour(Now())
time_min  = Minute(Now())
' default to false, and only set it to true if we are in opening hours '
showNormal = false

If (day_name = "wednesday" And IsBetween(time_hour, time_min, 19, 0, 20, 0)) Or _
   (day_name = "thursday" And IsBetween(time_hour, time_min, 20, 30, 21, 30)) Or _
   (day_name = "saturday" And IsBetween(time_hour, time_min, 17, 0, 18, 0)) Then
    ' we are open :) '
    showNormal = true
End If
Function IsNormalTime(dDateTime)
'// Default is true
IsNormalTime = True
'// Check day of week and set start/end times 
dim tStart, tEnd
select case WeekDay(dDateTime)
    case 4 '// Wednesday
        IsNormalTime = False
        tStart =  cDate("20:30:00")
        tEnd =  cDate("21:30:00")
    case 5 '// Thursday
        tStart =  cDate("19:00:00")
        tEnd =  cDate("20:00:00")
    case 7 '// Saturday
        tStart =  cdate("17:00:00")
        tEnd =  cDate("18:00:00")
    case else
        Exit Function
end select
'// Get time part only
dim dTimeOnly: dTimeOnly = dDateTime - FIX(dDateTime)
'// Check time against start/end times
select case true
    Case dTimeOnly < tStart, dTimeOnly >= tEnd
        exit Function
End Select
'// INVERT NORMAL TIME
IsNormalTime = Not IsNormalTime
END Function