2012-06-27 53 views
2

我創建了一個應用程序來顯示新聞稿,一旦達到目標日期和時間,並想知道是否從服務器或客戶端獲得時間,因爲我想使用服務器的時間,以便有人不會爲了看到而更改時鐘。使用VBScript和ASP Classic的服務器時間

這裏是我的代碼:

<% 
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分,然後部分將顯示。我主要是問,因爲我想澄清這是客戶端還是服務器端時間。

回答

5

這將是服務器端,因爲這是執行ASP代碼的地方。爲了獲得客戶端日期時間,您需要使用腳本在瀏覽器中運行 - 通常是JavaScript。

相關問題