星空网 > 软件开发 > Java

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>



原标题:php和js一起实现倒计时功能

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境ChatGPT,永久免费使用!抓紧注册!:https://www.ikjzd.com/articles/1660461974951325697
跨境电商财务如何做账?从五个方面探讨,管控财务风险和提高效率:https://www.ikjzd.com/articles/1660485786782691329
为什么每个亚马逊卖家,人手一个独立站?:https://www.ikjzd.com/articles/16605
东南亚市场攻略:如何利用海外网红实现品牌曝光与销售增长:https://www.ikjzd.com/articles/1660547908199804930
英国VAT注册-亚马逊英国站用户如何申请VAT合规延期?:https://www.ikjzd.com/articles/1660574137463808001
选品、运营有问题,该如何创造爆款?这4个数据是关键:https://www.ikjzd.com/articles/1660582344491999233
深圳有没有比较好玩的景点 深圳有没有比较好玩的景点推荐一下:https://www.vstour.cn/a/366175.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流