How to show only hours and minutes from javascript date.toLocaleTimeString()?

前端 未结 5 1201
無奈伤痛
無奈伤痛 2020-12-16 11:02

Can anyone please help me get the HH:MM am/pm format instead of HH:MM:SS am/pm.

My javascript code is :



        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 12:03

    Here is a more general version of this question, which covers locales other than en-US. Also, there can be issues parsing the output from toLocaleTimeString(), so CJLopez suggests using this instead:

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

提交回复
热议问题