经典ASP如果触发命令,则检查是否已经过了1分钟

时间:2018-05-10 19:52:00

标签: asp-classic

我正在尝试检查当前时间VS数据库时间并显示一条消息 这是我的第二次尝试,但它无法正常工作,如下所示,我做错了。请帮忙。

感谢。

   <%
    Function ConvertToUnixTimeStamp(input_datetime) 'As String
        Dim d : d = CDate(input_datetime)
        ConvertToUnixTimeStamp = CStr(DateDiff("s", "01/01/2018 00:00:00", d))
    End Function


    'Response.write ("<BR><BR>Current Time Now: ") & ConvertToUnixTimeStamp(Now)


    time_from_db = 11293015 + 60 'This would be the time from the database. It is generated using ConvertToUnixTimeStamp(Now) + 60

    Response.write "Current Time: " & ConvertToUnixTimeStamp(Now) & "<BR><BR>"
    Response.write "Time from DB: " & time_from_db & "<BR><BR>"
    Response.write "<BR><BR>"
    Response.write "Update DB with this time (Added 1 minute): " & ConvertToUnixTimeStamp(Now) + 60 & "<BR><BR>"


    If ConvertToUnixTimeStamp(Now) > time_from_db then 
        Response.write("<BR>Current Time is Greaten then DB")
    else
        Response.write("<BR>DB Time is Newer then Current Time")
    end if

    %>

1 个答案:

答案 0 :(得分:1)

If ConvertToUnixTimeStamp(Now) > time_from_db then 

这将永远不会返回true,因为您的函数将时间转换为STRING,并且字符串不能大于另一个字符串。

我在代码中做了一些小改动,主要是将变量显式转换为数据类型(例如:CInt,CStr等)。

<%
    Function ConvertToUnixTimeStamp(input_datetime) 'As String
        Dim d : d = CDate(input_datetime)
        ConvertToUnixTimeStamp = DateDiff("s", "01/01/2018 00:00:00", d)
    End Function


    'Response.write ("<BR><BR>Current Time Now: ") & ConvertToUnixTimeStamp(Now)


    time_from_db = 11293015 + 60 'This would be the time from the database. It is generated using ConvertToUnixTimeStamp(Now) + 60

    Response.write "Current Time: " & ConvertToUnixTimeStamp(Now) & "<BR><BR>"
    Response.write "Time from DB: " & time_from_db & "<BR><BR>"
    Response.write "<BR><BR>"
    Response.write "Update DB with this time (Added 1 minute): " & ConvertToUnixTimeStamp(Now) + 60 & "<BR><BR>"


    If CInt( ConvertToUnixTimeStamp(Now) ) > time_from_db then 
        Response.write("<BR>Current Time is Greaten then DB")
    else
        Response.write("<BR>DB Time is Newer then Current Time")
    end if

    %>