How to format $.now() with Jquery

前端 未结 7 1900
醉话见心
醉话见心 2021-01-11 09:38

$.now() gives me the time as miliseconds. I need to show it something like hh:mm:ss

How can I do that in Jquery?

7条回答
  •  天涯浪人
    2021-01-11 10:28

    I'm way late to this, but thought i'd just throw this little snippet out there for the masses. This is something I use just to get a quick localized timestamp. It's pretty clean and handy.

    function getStamp() {
        var d = new Date();
    
        var mm = d.getMilliseconds(), hh = d.getHours(),
            MM = d.getMinutes(), ss = d.getSeconds();
    
        return (hh < 10 ? "0" : "") + hh + (MM < 10 ? ":0" : ":") + MM + (ss < 10 ? ":0" : ":") + ss + ":" + mm;
    };
    

提交回复
热议问题