javascript 倒計時代碼_時間日期

來源:互聯網
上載者:User
<SCRIPT type="text/javascript"> <!-- var target=[] var time_id=[] function show_date_time_0(){ setTimeout("show_date_time_0()", 1000); for (var i=0,j=target.length;i<j;i++){ today=new Date(); timeold=target[i]-today.getTime(); sectimeold=timeold/1000; secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000; e_daysold=timeold/msPerDay; daysold=Math.floor(e_daysold); e_hrsold=(e_daysold-daysold)*24; hrsold=Math.floor(e_hrsold); e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); if (daysold<0) { document.getElementById(time_id[i]).innerHTML="逾期,倒計時已經失效"; } else { if (daysold<10) {daysold="0"+daysold} if (daysold<100) {daysold="0"+daysold} if (hrsold<10) {hrsold="0"+hrsold} if (minsold<10) {minsold="0"+minsold} if (seconds<10) {seconds="0"+seconds} if (daysold<3) { document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+":"+minsold+":"+seconds+"</font>"; } else { document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+":"+minsold+":"+seconds; } } } } setTimeout("show_date_time_0()", 100); //--> </sCRIPT> <div id="TimeCounter_0" ></div> <SCRIPT> //設定目標時間(數組元素) //target[target.length]=new Date(年,月-1,日,時,分,秒).getTime() target[target.length]=new Date(2015,11,15,00,00,00).getTime(); //設定倒計時顯示地址(數組元素) time_id[time_id.length]="TimeCounter_0" </sCRIPT>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.