JS倒计时代码-精确到秒

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<head>
<title> 演示实例:倒计时效果-精确到秒 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,CNLei.y.l@gmail.com">
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="JavaScript">
<!-- //
function GetRTime(){
var EndTime= new Date(2006,5,10,0,0); //截止时间:2006年6月10日0时0分
var NowTime = new Date();
var nMS =EndTime.getTime() - NowTime.getTime();
var nD =Math.floor(nMS/(1000 * 60 * 60 * 24));
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
if(nD>= 0){
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS;
setTimeout("GetRTime()",1000);
} else {
document.getElementById("CountMsg").innerHTML="世界杯已经圆满结束!";
}
}
window.onload=GetRTime;
// -->
</script>
</head>
<body>
<div id="CountMsg">
今天距离2006世界杯开赛还有<strong id="RemainD">XX</strong><strong id="RemainH">XX</strong><strong id="RemainM">XX</strong><strong id="RemainS">XX</strong>
</div>
</body>
</html>