Leading zeros in minutes

后端 未结 5 1922
眼角桃花
眼角桃花 2020-12-31 17:20

I created a clock to be placed in the header of my website. The time is not displaying a zero for minutes < 10. For example if the time is 10:50, it will only show 10:5 ,

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 18:06

    You can just grab the first 5 characters of the time string.

    (new Date()).toTimeString().substr(0,5)
    

提交回复
热议问题