function init(){ var now=new Date().getTime(); var endtime=new Date(2012,1,12,20,45,0).getTime(); var duringtime=endtime-now; var day=parseInt(duringtime/86400000); var hour=parseInt(duringtime%86400000/3600000); var minute=parseInt(duringtime%3600000/60000); var seconds=parseInt(duringtime%60000/1000); var millseconds=parseInt(duringtime%1000); alert(day+"天"+hour+"小时"+minute+"分钟"+seconds+"秒"+millseconds+"毫秒"); } 像这样 注意的是new Date(2012,1,12,20,45,0)指的是2012年2月12日20点45分0秒 而不是一月 月份要减一的 呵呵
<body> <div id="show"></div> <script> var expire = "2012/12/24/12:00:00";
setInterval(function(){ var now, countdown, day, minute, second, buffer, string; now = new Date(); countdown = new Date(expire).getTime() - now.getTime();
var now=new Date().getTime();
var endtime=new Date(2012,1,12,20,45,0).getTime();
var duringtime=endtime-now;
var day=parseInt(duringtime/86400000);
var hour=parseInt(duringtime%86400000/3600000);
var minute=parseInt(duringtime%3600000/60000);
var seconds=parseInt(duringtime%60000/1000);
var millseconds=parseInt(duringtime%1000);
alert(day+"天"+hour+"小时"+minute+"分钟"+seconds+"秒"+millseconds+"毫秒");
}
像这样 注意的是new Date(2012,1,12,20,45,0)指的是2012年2月12日20点45分0秒 而不是一月 月份要减一的 呵呵
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="show"></div>
<script>
var expire, now, countdown, year, month, day, minute, second, buffer;
expire = "2012/12/24/12:00:00";
now = new Date();
countdown = new Date(expire).getTime() - now.getTime();
buffer = 24 * 60 * 60 * 1000;
day = Math.floor(countdown / buffer);
countdown = countdown % buffer;
buffer = 60 * 1000;
minute = Math.floor(countdown / buffer);
countdown = countdown % buffer;
buffer = 1000;
second = countdown / buffer;
countdown = countdown % buffer;
var str = day + "天" + minute + "分" + second + "秒";
document.getElementById("show").innerHTML = str;
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="show"></div>
<script>
var expire = "2012/12/24/12:00:00";
setInterval(function(){
var now, countdown, day, minute, second, buffer, string;
now = new Date();
countdown = new Date(expire).getTime() - now.getTime();
buffer = 24 * 60 * 60 * 1000;
day = Math.floor(countdown / buffer);
countdown = countdown % buffer;
buffer = 60 * 1000;
minute = Math.floor(countdown / buffer);
countdown = countdown % buffer;
buffer = 1000;
second = countdown / buffer;
countdown = countdown % buffer;
string = day + "天" + minute + "分" + second + "秒";
document.getElementById("show").innerHTML = string;
}, 10);
</script>
</body>
</html>
countdown = Math.floor(countdown / 1000);