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. MySQL开发技巧

    MySQL基础表和数据 如何进行行列转换 行转列 场景:报表统计(sum()).汇总显示表数据:select * from score; 希望达到的效果 cross join SQL如下: selec ...

  2. 铁轨(UVa 514)

    利用栈实现 C++11 代码如下: #include<iostream> #include<stack> using namespace std; #define maxn 1 ...

  3. 【LOJ】#2558. 「LNOI2014」LCA

    题解 当年LN还是有专门的省选题的,但是还不如没有 看到这道题,我就想到了一个清晰易懂,简单好写,代码优美的树链剖分线段树套主席树的\(O(q\log^{3}n)\)做法,且就5组数据出题人肯定是不会 ...

  4. centos7+python3.6+nginx+uwsgi+django2的搭建笔记

    公司需上线一套python编写的代码,需要给搭建一套环境  ,本次采用centos7+python3.6+nginx+uwsgi2+django2+mysql5.7的方式来进行搭建 写在部署前 在线上 ...

  5. hdoj2191 珍惜现在,感恩生活(01背包 || 多重背包)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2191 思路 由于每种大米可能不止一袋,所以是多重背包问题,可以直接使用解决多重背包问题的方法,也可以将 ...

  6. Ionic实战二:购物车

    用户名密码都为空 此app功能主要有如下 1.首页轮播和商品列表展示 2.左侧侧滑页面分类展示 3.商品详情页面展示 以及购买 4.购物车 订单填写 支付等页面          

  7. "characterEncoding" must end with the ';' delimiter.

    17/04/20 17:27:10 FATAL conf.Configuration: error parsing conf file:/usr/local/apache-hive-1.2.2-bin ...

  8. CSUOJ 1005 Binary Search Tree analog

    Description Binary Search Tree, abbreviated as BST, is a kind of binary tree maintains the following ...

  9. SKLearn数据集API(二)

    注:本文是人工智能研究网的学习笔记 计算机生成的数据集 用于分类任务和聚类任务,这些函数产生样本特征向量矩阵以及对应的类别标签集合. 数据集 简介 make_blobs 多类单标签数据集,为每个类分配 ...

  10. 凡信(超仿微信Android版)开源了,内有源码下载 -

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 凡信(超仿微信Android版)开源了,内有源码下载 - IM Geek开发者社区-移动 ...