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

前端 未结 5 1197
無奈伤痛
無奈伤痛 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 11:50

    Use the Intl.DateTimeFormat library.

     function prettyDate2(time){
        var date = new Date(parseInt(time));
        var options = {hour: "numeric", minute: "numeric"};
        return new Intl.DateTimeFormat("en-US", options).format(date);
      } 
    

提交回复
热议问题