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

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

    I wanted it with date and the time but no seconds so I used this:

    var dateWithoutSecond = new Date();
    dateWithoutSecond.toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'});
    

    It produced the following output:

    7/29/2020, 2:46 PM

    Which was the exact thing I needed. Worked in FireFox.

提交回复
热议问题