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

    实现功能:静态页实现自动显示距离某未来时间的倒计时,精确到秒

    View Code
    <div class="rmain time">
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
          <tr>
            <td>日</td>
            <td>&nbsp;</td>
            <td>时</td>
            <td>&nbsp;</td>
            <td>分</td>
            <td>&nbsp;</td>
            <td>秒</td>
            </tr>
          <tr>
            <td height="40"><span id="strd"></span></td>
            <td>:</td>
            <td><span id="strh"></span></td>
            <td>:</td>
            <td><span id="strm"></span></td>
            <td>:</td>
            <td><span id="strs"></span></td>
            </tr>
        </table>
        </div>   
        <script type='text/javascript' language="javascript">
        var time_now_server, time_now_client, time_end, time_server_client, timerID;
        time_now_server = new Date();
        var time_end = new Date("July 24 15:00:00  2012");//January 1 10:30:00  2009
        var df1 = time_end.getTime() - time_now_server.getTime();
        time_server_client = df1;
        function show_time() {
            var time_now, time_distance, str_time;
            var int_day, int_hour, int_minute, int_second;
            var time_now = new Date();
            time_now = time_now.getTime() + time_server_client;
            time_distance = time_server_client;
            time_server_client -= 1000;
            df1 -= 1000;
            if (time_distance > 0) {
                int_day = Math.floor(time_distance / 86400000);
                time_distance -= int_day * 86400000;
                int_hour = Math.floor(time_distance / 3600000);
                time_distance -= int_hour * 3600000;
                int_minute = Math.floor(time_distance / 60000);
                time_distance -= int_minute * 60000;
                int_second = Math.floor(time_distance / 1000);
                if (int_hour < 10)
                    int_hour = "0" + int_hour;
                if (int_minute < 10)
                    int_minute = "0" + int_minute;
                if (int_second < 10)
                    int_second = "0" + int_second;
                document.getElementById("strd").innerHTML = int_day;
                document.getElementById("strh").innerHTML = int_hour;      //获取当前小时数(0-23)
                document.getElementById("strm").innerHTML = int_minute;    //获取当前分钟数(0-59)
                document.getElementById("strs").innerHTML = int_second;    //获取当前秒数(0-59)
                setTimeout("show_time()", 1000);
            }
            else {
                document.getElementById("strd").innerHTML = "0";
                document.getElementById("strh").innerHTML = "0";      //获取当前小时数(0-23)
                document.getElementById("strm").innerHTML = "0";    //获取当前分钟数(0-59)
                document.getElementById("strs").innerHTML = "0";    //获取当前秒数(0-59)   
                clearTimeout(timerID)
            }
        }
        setTimeout("show_time()", 1000);
    </script>
  • 相关阅读:
    断开ssh链接在后台继续运行命令
    linux 隐藏显示终端光标
    shell脚本中echo显示内容带颜色
    Linux/Unix下pid文件作用浅析
    使用autotools自动生成Makefile并在此之上使用dh-make生成可发布的deb程序包(详解)
    Linux的tmpfs文件系统
    kernel编译
    Qt之读取配置文件
    android之TCP客户端框架
    android之模拟器更新底层
  • 原文地址:https://www.cnblogs.com/judy0605/p/2577846.html
Copyright © 2011-2022 走看看