How to format $.now() with Jquery

前端 未结 7 2010
醉话见心
醉话见心 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();
    

提交回复
热议问题