How to format $.now() with Jquery

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

    new Date().toString().split(' ')[4]
    

    or

    new Date().toString().match(/\d{2}:\d{2}:\d{2}/)[0]
    

    The toString method is basically an alias for toLocaleString in most implementations. This will return the time in the user's timezone as opposed to assuming UTC by using milliseconds if you use getTime (if you use getMilliseconds you should be OK) or toUTCString.

提交回复
热议问题