zoukankan      html  css  js  c++  java
  • 倒计时

    <?php
    //php的时间是以秒算。js的时间以毫秒算
    date_default_timezone_set('PRC');
    //date_default_timezone_set("Asia/Hong_Kong");//地区

    $timestr = "2018-1-1 10:19:00";//倒计时时间
    $time = strtotime($timestr);//时间戳
    $nowtime = time();//当前时间戳

    if ($time>=$nowtime){
    $overtime = $time-$nowtime; //实际剩下的时间(单位/秒)
    }else{
    $overtime=0;
    }
    ?>
    <script type="text/javascript" src="__PUBLIC__/jquery-1.8.3.min.js"></script>
    <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>

    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    </html>
    <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>
    </body

  • 相关阅读:
    弹出层layer的使用
    SQL Server SQL分页查询
    C#过滤html标签
    SQLServer ForXmlPath应用
    js调用soapWebService服务
    MediaWiki使用指南
    阿里云金融云服务器配置
    VS无法启动 IISExpress web 服务器
    mysql服务突然丢失解决方案
    [k8s]通过openssl生成证书
  • 原文地址:https://www.cnblogs.com/lixiaomingtongxue/p/8143306.html
Copyright © 2011-2022 走看看