How do I use .toLocaleTimeString() without displaying seconds?

前端 未结 11 972
小蘑菇
小蘑菇 2020-12-07 15:56

I\'m currently attempting to display the user\'s time without displaying the seconds. Is there a way I can do this using Javascript\'s .toLocaleTimeString()?

Doing s

11条回答
  •  再見小時候
    2020-12-07 16:33

    You can try this, which is working for my needs.

    var d = new Date();
    d.toLocaleTimeString().replace(/:\d{2}\s/,' ');
    

    or

    d.toLocaleString().replace(/:\d{2}\s/,' ');
    

提交回复
热议问题