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 />");
            });

Javascript时间以及格式化秒的更多相关文章

  1. JavaScript 对时间日期格式化

    JavaScript 对时间日期格式化 // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位 ...

  2. 【转载】vue.js实现格式化时间并每秒更新显示功能示例

    引用:https://www.jb51.net/article/143351.htm 这篇文章主要介绍了vue.js实现格式化时间并每秒更新显示功能,结合实例形式分析了vue.js时间格式化显示与基于 ...

  3. javascript之input获取的时间减1秒&&t时间恢复

    将输入得到的时间减少1秒:20:00:00  ———  19:59:59    方法一:普通时间转换 endDateMap(date){ var h = new Date(date).getHours ...

  4. 第一百零四节,JavaScript时间与日期

    JavaScript时间与日期 学习要点: 1.Date类型 2.通用的方法 3.格式化方法 4.组件方法 ECMAScript提供了Date类型来处理时间和日期.Date类型内置一系列获取和设置日期 ...

  5. JavaScript 时间与日期处理实战:你肯定被坑过

    本部分的知识图谱请参考编程语言知识图谱-时间与日期. 本文JavaScript 时间与日期处理实战:你肯定被坑过从属于笔者的Web 前端入门与最佳实践中 JavaScript 入门与最佳实践系列文章. ...

  6. javascript 时间操作

    javascript时间函数 javascript提供了Date对象来进行时间和日期的计算.Date对象有多种构造函数: 1.dateObj=new Date() //当前时间 2.dateObj=n ...

  7. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  8. javascript 的Date 格式化, 模仿shell中date命令的格式

    原文:javascript 的Date 格式化, 模仿shell中date命令的格式 shell 中显示当前的日期 [root@localhost]$ date '+%Y-%m-%d %H:%M:%S ...

  9. Java如何格式化秒数?

    在Java中,如何格式化秒数? 此示例使用SimpleDateFormat类的SimpleDateFormat('ss')构造函数和sdf.format(date)方法格式化秒数. package c ...

随机推荐

  1. jquery 分页 下拉框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. Decorator 装饰

    意图 动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator模式相比生成子类更为灵活. 结构 Component:定义一个对象接口,可以给这些对象动态地添加职责:(纯虚函数) Conc ...

  3. Zookeeper服务器集群的搭建与操作

    ZooKeeper 作用:Zookeeper 可以用来保证数据在zk集群之间的数据的事务性一致(原子操作). 介绍:Zookeeper 是 Google 的 Chubby一个开源的实现,是 Hadoo ...

  4. Ionic Js二:背景层

    我们经常需要在 UI 上,例如在弹出框.加载框.其他弹出层中显示或隐藏背景层. 在组件中可以使用\(ionicBackdrop.retain()来显示背景层,使用\)ionicBackdrop.rel ...

  5. thinphp中auth认证方法使用

    一.获取Auth类1.ThinkPHP3.1.3完整版:http://www.thinkphp.cn/down/338.html2.OneThink1.0正式版:https://github.com/ ...

  6. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. JAVA基础知识之jdk下载与安装

    一.下载JDK 下载网址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 如果 ...

  8. Node.js CVE-2017-14849复现(详细步骤)

    0x00 前言 早上看Sec-news安全文摘的时候,发现腾讯安全应急响应中心发表了一篇文章,Node.js CVE-2017-14849 漏洞分析(https://security.tencent. ...

  9. [leetcode tree]95. Unique Binary Search Trees II

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...

  10. [leetcode trie]212. Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...