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

前端 未结 11 975
小蘑菇
小蘑菇 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:46

    You can always set the options, based on this page you can set, to get rid of the seconds, something like this

    var dateWithouthSecond = new Date();
    dateWithouthSecond.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
    

    Supported by Firefox, Chrome, IE9+ and Opera. Try it on your web browser console.

提交回复
热议问题