且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户登录后如何显示计时器?

更新时间:2023-12-04 11:18:58

问题在于,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