I need to determine the length of seconds. If the second is only one character long, I want to add a 0 in front of it. Otherwise, no action is needed. Below is my code:
<p>Click the button to show the current number of seconds.</p>
<p id="demo"></p>
<script>
var d = new Date();
var n = d.getSeconds();
var z = (n < 10) ? "0" + n : n;
document.getElementById("demo").innerHTML = z;
</script>