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() {("input[name=start]").click(function() {("#console").append("<span style=\"color: #0F0\">Timer started.</span<br />"); 
                timer = .timer(timeout, function() {.timer(timeout, function() {("#console").append("Timer completed.<br />"); 
                }); 
            });

            ("input[name=stop]").click(function() {                    if(timer.stop()) {("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()) {("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=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 />"); 
            });

本文转自最课程陆敏技博客园博客,原文链接:http://www.cnblogs.com/luminji/p/3408444.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值