toLocaleTimeString() always showing leading zero

I would like to display this as something like: 4:26 PM.

But what I keep getting is: 04:26 PM.

If I remove the hour and minute options from toLocaleTimeString(), it works, but it also displays seconds, which I don’t want.

myClock();
function myClock() { 
    var d = new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});   
    document.getElementById("clock").innerHTML = d; 
}
setInterval(myClock, 1000);
<div id="clock"></div>

22 thoughts on “toLocaleTimeString() always showing leading zero”

Leave a Comment