How to format $.now() with Jquery

前端 未结 7 1885
醉话见心
醉话见心 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:42

    I'd suggest just using the Javascript Date object for this purpose.

        var d = new Date();
        var time = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    

    Edit: I just came across the method below, which covers formatting issues such as the one mike-samuel mentioned and is cleaner:

        var time = d.toLocaleTimeString();
    
    0 讨论(0)
提交回复
热议问题