+ 5
Rather than manually constructing the string from the time components, you could also use the built-in formatter. var d = new Date(); heading1.textContent = d.toLocaleTimeString('en-GB'); The default time format for en-GB locale is 24 hours, with leading zeroes.
4th Mar 2024, 1:06 PM
Tibor Santa
Tibor Santa - avatar
+ 3
heading1.textContent = String(h).padStart(2, '0') + ":" + m + ":" + s;
4th Mar 2024, 12:12 PM
Bob_Li
Bob_Li - avatar