2

我创建了一个应用程序以在达到目标日期和时间后显示新闻稿,并想知道这是从服务器还是客户端获取时间,因为我想使用服务器的时间,这样别人就不会只需更改他们的时钟以查看它。

这是我的代码:

    <%
dim strDate
dim strTime
dim strTarget_time
dim strTarget_date
dim strBreak
dim strRuleBreak
dim strToday

strDate = Date()
strTime = Time()
strright_now = Now()
strTarget_time = "3:27:00 PM"
strTarget_date = "6/26/2012"
strBreak = "<br />"
strRuleBreak = "<br /><hr><br />"
strToday = Now()

response.write("<h2>TEST VARIABLES</h2>")
response.write("<p><strong>Today's date:</strong> " & strDate & strBreak)
response.write("<strong>Current time:</strong> " & strTime & strBreak)
response.write("<strong>Target date:</strong> " & strTarget_date & strBreak)
response.write("<strong>Target time:</strong> " & strTarget_time & "</p>")
response.write(strRuleBreak)

'TIME TESTER
response.write("<h2>TIME TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target time of: " & strTarget_time & "</nobr></p>")
if strTime >= cdate(strTarget_time) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target time of: " & strTarget_time & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target time of: " & strTarget_time & "</p>")
end if

response.write(strRuleBreak)

'DATE TESTER
response.write("<h2>DATE TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target date of: " & strTarget_date & "</nobr></p>")
if strToday >= cdate(strTarget_date) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target date of: " & strTarget_date & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target date of: " & strTarget_date & "</p>")

end if 
response.write(strRuleBreak)

'DATE AND TIME TESTER
response.write("<h2>DATE AND TIME TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target of: " & strTarget_date & "&nbsp;-&nbsp;" & strTarget_time & "</nobr></p>" & strBreak)
if strToday >= cdate(strTarget_date) AND strTime >= cdate(strTarget_time) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target of: " & strTarget_date & "&nbsp;-&nbsp;" & strTarget_time & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target of: " & strTarget_date & "&nbsp;-&nbsp;" & strTarget_time & "</p>")

end if 
response.write(strRuleBreak)

%>

因此,在这种情况下,如果时间和日期是 2012 年 6 月 26 日下午 3:27 之后,则该部分将显示。我主要是问,因为我想澄清这是使用客户端还是服务器端时间。

4

1 回答 1

5

这将是服务器端,因为这是执行 ASP 代码的地方。为了获取客户端日期时间,您需要使用脚本在浏览器中运行 - 通常是 JavaScript。

于 2012-06-27T13:44:09.773 回答