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. Codeforces Round #146 (Div. 1) C - Cyclical Quest 后缀自动机+最小循环节

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...

  2. 极简操作无需root隐藏S8导航栏和状态栏

    距离三星Galaxy S8国行发布快一个礼拜了,相信论坛不少小同伴已经拿到手,许多人和我一样被那块全视曲面屏给诱惑剁手的,当拿到手把玩一段时间后却發现这么美的一块屏幕居然大部分应用上下都有一行碍眼的状 ...

  3. 8-3 Bits Equalizer uva12545

    题意: 给出字符串s包含'0' '1' '?'; 再给出字符串t只包含01: 现在我们可以对S做三个操作:把0变成1,把?变成0或1,任意两个位置交换: 问最少操作几次s == t: 贪心 默认除去那 ...

  4. .NET常用的异常类型及其中文说明

    基异常类型: 类 说明 System.Exception 所有异常的基类型 System.ApplicationException 发生非致命应用程序错误时引发的异常 System.SystemExc ...

  5. Python 学习经历分享

    如果说 Java 是亲儿子的话,那么 Python 应该就是干儿子了.看了一下所有关于 Python 的笔记,我发现原来我在 4 月份的时候就已经涉足 Python 了,但是到目前为止才真正算做出了一 ...

  6. 用户管理和FTP服务配置

    批量创建用户 python脚本:creuser.py import osulist=open('usernames','r')for x in ulist: cmd="useradd -g ...

  7. 汉化 的 空指针 bug

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha nulljava.lang.NullPointerException at com.an ...

  8. TCP的三次握手与四次释放

    TCP的三次握手与四次释放 一.名词解释     序列号seq:占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生:给字节编上序号后,就给 ...

  9. Codecademy python

    #1 print "Welcome to Python!" #2 my_variable = #3 # Set the variables to the values listed ...

  10. JVM垃圾回收(GC)流程

    /* 首先介绍一下JVM中堆内存的组成: JVM堆内存主要由三部分组成: (1)新生代: 伊甸园区,存活区,伸缩区 (2)老年代: 老年区,伸缩区 (3)元空间(永久代): 元空间,伸缩区 注意:JD ...