I wanted to make a digital live clock and I did it, but for numbers less than zero it does it without a 0 next to it, I want it to have zero next to it. For example: 18:35:05 I think we're going to add an if and write -- < 10, but I couldn't find what to write in the context of the condition.
function clock() {
var hour = document.getElementById('hour');
var minute = document.getElementById('minute');
var second = document.getElementById('second');
var h = new Date().getHours();
var m = new Date().getMinutes();
var s = new Date().getSeconds();
hour.innerHTML = h;
minute.innerHTML = m;
second.innerHTML = s;
}
var interval = setInterval(clock, 1000);
.current-time {
display: flex;
position: relative;
justify-content: space-between;
width: 45%;
}
.time-text {
display: table;
position: relative;
justify-content: flex-start;
vertical-align: middle;
margin: 0;
width: 35%;
}
.time-text p {
margin: 0;
}
#clock {
display: table;
position: relative;
justify-content: flex-end;
vertical-align: middle;
margin: 0;
width: 65%;
}
<html>
<body>
<div class="current-time">
<div class="time-text">
<p>Time :</p>
</div>
<div id="clock">
<span id="hour">00</span> :
<span id="minute">00</span> :
<span id="second">00</span>
</div>
</div>
</body>
</html>