世界末日倒计时 js代码

<div id="container">离世界末日还有 <span id="downtime" style="color:red"></span></div>
<script>

function downTime(){
 var timeout = window.setTimeout(downTime, 100);
 var endTime=new Date("12-21-2011 0:0:0");//改成你的计时日期
 var today=new Date();
 var timeold=(endTime.getTime()-today.getTime());
 if(timeold <= 100){
    window.clearTimeout(timeout);
    document.getElementById("container").innerHTML = "原来没事啊,虚惊一场!";
    return;
 }
 var sectimeold=timeold/1000;
 var secondsold=Math.floor(sectimeold);
 var msPerDay=24*60*60*1000;
 var e_daysold=timeold/msPerDay;
 var daysold=Math.floor(e_daysold);
 var e_hrsold=(e_daysold-daysold)*24;
 var hrsold=Math.floor(e_hrsold);
 var e_minsold=(e_hrsold-hrsold)*60;
 var minsold=Math.floor((e_hrsold-hrsold)*60);
 var e_seconds=(e_minsold-minsold)*60;
 var seconds=Math.floor((e_minsold-minsold)*60);
 var decimals = Math.floor((e_seconds-seconds)*10);
 document.getElementById("downtime").innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"."+decimals+"秒" ;
}
downTime();

</script>

你可能感兴趣的:(倒计时)