php和js一起實現倒計時功能


里獲取的php服務端的時間 純JS是獲取客服端時間!

<?php //php的時間是以秒算。js的時間以毫秒算 date_default_timezone_set('PRC'); //date_default_timezone_set("Asia/Hong_Kong");//地區 $timestr = "2015-4-3 18:50:00";//倒計時時間 $time = strtotime($timestr);//時間戳 $nowtime = time();//當前時間戳 if ($time>=$nowtime){ $overtime = $time-$nowtime; //實際剩下的時間(單位/秒) }else{ $overtime=0; } ?> <script language="JavaScript"> var runtimes = 0; function GetRTime(){ var nMS = <?php echo $overtime; ?>*1000-runtimes*1000; if (nMS>=0){ var nD=Math.floor(nMS/(1000*60*60*24))%24; var nH=Math.floor(nMS/(1000*60*60))%24; var nM=Math.floor(nMS/(1000*60)) % 60; var nS=Math.floor(nMS/1000) % 60; document.getElementById("RemainD").innerHTML=nD; document.getElementById("RemainH").innerHTML=nH; document.getElementById("RemainM").innerHTML=nM; document.getElementById("RemainS").innerHTML=nS; runtimes++; if(nD==0){ //天數0 隱藏天數 document.getElementById("hideD").style.display="none"; if(nH==0){ //數0 隱藏天數 document.getElementById("hideH").style.display="none"; if(nM==0){ document.getElementById("hideM").style.display="none"; if(nS==0){ alert("倒計時完畢"); } } } } setTimeout("GetRTime()",1000); } } window.onload = function() { GetRTime(); } </script> <h4>開售還有 <span id="hideD"><strong id="RemainD"></strong>天</span> <span id="hideH"><strong id="RemainH"></strong>小時</span><span id="hideM"> <strong id="RemainM"></strong>分鍾</span> <span id="hideS"><strong id="RemainS"></strong>秒</span></h4>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM