zoukankan      html  css  js  c++  java
  • Javascript时间以及格式化秒

    var now = new Date();
    timer = $.timer(timeout, function () {
        var sec_num = Math.ceil((now.getTime() - startTime.getTime()) / 1000);
        showPaperTimer(now, sec_num);
        if (sec_num % 60 == 0) {

        }
    });

     

    function showPaperTimer(now, sec_num) {
        var nowStr = now.getFullYear() + '-';
        nowStr += now.getMonth() + 1 + '-';
        nowStr += now.getDate() + ' ';
        nowStr += now.getHours() + ':';
        nowStr += now.getMinutes() + ':';
        nowStr += now.getSeconds();

        var hours = Math.floor(sec_num / 3600);
        var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
        var seconds = sec_num - (hours * 3600) - (minutes * 60);
        if (hours < 10) { hours = "0" + hours; }
        if (minutes < 10) { minutes = "0" + minutes; }
        if (seconds < 10) { seconds = "0" + seconds; }
        var time0 = hours + ':' + minutes + ':' + seconds;

        $("#times").html("当前时间:" + str + ",已耗时:" + time0);
    }

     

    其中,$.timer是一个Jq时钟,来自于http://plugins.jquery.com/timer/,其常用操作有:

    var timeout = 1000;
                var timer;
                $("input[name=start]").click(function() {
                    $("#console").append("<span style="color: #0F0">Timer started.</span<br />");
                    timer = $.timer(timeout, function() {
                        $("#console").append("Timer completed.<br />");
                    });
                });

                $("input[name=stop]").click(function() {
                    if(timer.stop()) {
                        $("#console").append("<span style="color: #F00">Timer stopped.</span<br />");
                    }
                });

                $("input[name=pause]").click(function() {
                    if(timer.pause()) {
                        $("#console").append("<span style="color: #FF0">Timer paused.</span<br />");
                    }
                });

                $("input[name=resume]").click(function() {
                    if(timer.resume()) {
                        $("#console").append("<span style="color: #F00">Timer resumed.</span<br />");
                    }
                });
                $("input[name=reset]").click(function() {
                    timer.stop();
                    timeout = prompt("Reset timeout too:", 500);
                    timer.reset(timeout);
                    $("#console").append("<span style="color: #00F">Timer reset.</span<br />");
                });

  • 相关阅读:
    记一次java程序内存溢出问题
    js 对象数据观察者实现
    requirejs和seajs使用感受
    maven根据不同的运行环境,打包不同的配置文件
    Quartz .net 一直运行失败
    Sql2008R2 日志无法收缩解决方案
    win7 64位英文版 ado驱动
    KB4284826 远程桌面发生身份验证错误,要求的函数不受支持
    Delphi System.zip patch with ZIP64 and LZMA supports
    native excel 文件已经打开的判断
  • 原文地址:https://www.cnblogs.com/luminji/p/3408444.html
Copyright © 2011-2022 走看看