js倒计时
<span id="countdown_hour"></span>:
<span id="countdown_minute"></span>:
<span id="countdown_second"></span>
<script type="text/javascript">
var nowTime = new Date().getTime();
var endTime = new Date("Jun 18, 2011 10:00:00").getTime();
var countDownTimer = null;
function get2Num(a) { if (a < 10) { return "0" + a } return "" + a; }
function countDown() {
var _diff = parseInt((endTime - nowTime) / 1000);
var _day = parseInt(_diff / 3600 / 24);
var _hour = Math.floor((_diff / 3600) % 24);
var _minute = Math.floor((_diff / 60) % 60);
var _second = Math.floor(_diff % 60);
_hour = _day > 0 ? (_day * 24) + _hour : _hour;
if (_diff <= 0) {
window.clearInterval(countDownTimer);
updateLED(0, 0,0);
return;
}
updateLED(_hour,_minute,_second);
nowTime += 1000;
}
function updateLED(h, m, s) {
document.getElementById("countdown_hour").innerHTML = get2Num(h);
document.getElementById("countdown_minute").innerHTML = get2Num(m);
document.getElementById("countdown_second").innerHTML = get2Num(s);
}
countDownTimer = window.setInterval(countDown, 1000);
</script>
<span id="countdown_minute"></span>:
<span id="countdown_second"></span>
<script type="text/javascript">
var nowTime = new Date().getTime();
var endTime = new Date("Jun 18, 2011 10:00:00").getTime();
var countDownTimer = null;
function get2Num(a) { if (a < 10) { return "0" + a } return "" + a; }
function countDown() {
var _diff = parseInt((endTime - nowTime) / 1000);
var _day = parseInt(_diff / 3600 / 24);
var _hour = Math.floor((_diff / 3600) % 24);
var _minute = Math.floor((_diff / 60) % 60);
var _second = Math.floor(_diff % 60);
_hour = _day > 0 ? (_day * 24) + _hour : _hour;
if (_diff <= 0) {
window.clearInterval(countDownTimer);
updateLED(0, 0,0);
return;
}
updateLED(_hour,_minute,_second);
nowTime += 1000;
}
function updateLED(h, m, s) {
document.getElementById("countdown_hour").innerHTML = get2Num(h);
document.getElementById("countdown_minute").innerHTML = get2Num(m);
document.getElementById("countdown_second").innerHTML = get2Num(s);
}
countDownTimer = window.setInterval(countDown, 1000);
</script>