[Ctrl+A 全選 注:如需引入外部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-2012 0:0:0");//改成你的計時日期 var today=new Date(); var timeold=(endTime.getTime()-today.getTime()); if(timeold <= 100){ window.clearTimeout(timeout); document.getElementByIdx_x("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.getElementByIdx_x("downtime").innerHTML=daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"."+decimals+"秒" ; } downTime(); </script>