判斷是否到達指定時間,可以精確到秒
阿新 • • 發佈:2018-03-02
OS function 模擬考試 div ctype repl 考試 con element
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>判斷是否到達指定時間,可以精確到秒</title>
<SCRIPT type="text/javascript">
function $$(id){
return document.getElementById(id);
}
function dateDiff(date1, date2)
{
date1 = date1.replace("年","-").replace("月","-").replace("日","");
date2 = date2.replace("年","-").replace("月","-").replace("日","");
date1 = new Date(date1.replace(/-/g, "/"));
date2 = new Date(date2.replace(/-/g, "/"));
if(Date.parse(date2) - Date.parse(date1) >= 0){
return true;
}
return false;
}
function startexam(){
var sstime=$$(‘sstime‘).innerHTML;
var eetime=$$(‘eetime‘).innerHTML;
var svtime=$$(‘svtime‘).innerHTML;
var res=dateDiff(sstime, svtime);
alert(res);
if(!res){
alert(‘還沒有到考試時間。‘);
return;
}else{
alert(‘已過考試開始時間。流程繼續。‘);
}
var res2=dateDiff(eetime, svtime);
if(res2){
alert(‘此場次考試已過期。‘);
return;
}
alert(‘開始考試。‘);
}
</SCRIPT>
</head>
<body>
<table>
<tr >
<td>考試開始時間</td>
<td>
<span id="sstime">2012-06-14 17:00</span>
</td>
</tr>
<tr>
<td>考試結束時間:</td>
<td>
<span id="eetime">2012-06-14 17:34</span>
</td>
</tr>
<tr>
<td>當前服務器時間:</td>
<td>
<span id="svtime">2012-06-14 17:35</span></td>
</tr>
<tr>
<td>
<input type="button" value="開始模擬考試" onclick="startexam();"/>
</td>
</tr>
</td>
</tr>
</table>
</body>
</html>
判斷是否到達指定時間,可以精確到秒