用户登录后如何显示计时器? [英] How to show timer after user logged?

查看:81
本文介绍了用户登录后如何显示计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户登录后显示计时器是代码:

I want to show timer after user login here is code :

演示:小提琴

function startTimer_session()
{   
    var today = new Date();            
    var h=today.getHours() - login.getHours();
    var m=today.getMinutes() - login.getMinutes();
    var s=today.getSeconds() - login.getSeconds();
    // add a zero in front of numbers<10
    h=checkTime(h);
    m=checkTime(m);
    s=checkTime(s);
    $('#user-timer').html(h+":"+m+":"+s);
    timer=setTimeout(function(){startTimer_session()},1000);
}

但是它不能正确显示,为什么?

but it does not show properly, why?

推荐答案

问题在于,today.getSeconds小于login.getSeconds.

The problem is that today.getSeconds is less that login.getSeconds.

您需要在整个日期中进行减法运算,然后进行零件运算.

You need to do the subtraction on the full date and then take the parts.

最小的变化是:

    var today = new Date(); 
    var d = new Date(today - login);
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();

或使用Satpal显示的日期格式

Or use the date formatting that Satpal showed

这篇关于用户登录后如何显示计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆