JavaScript
- 4 ответа
- 0 вопросов
1
Вклад в тег
<div> Current Time
<span id="clock"></span>
</div>
window.onload = function(){
function showClock(){
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var sec = time.getSeconds();
var timeFormatter = digitFormatter(hour)+':'+digitFormatter(minute)+':'+digitFormatter(sec);
var clock = document.getElementById("clock");
clock.textContent = timeFormatter;
}
function digitFormatter(num){
if(num<10){
return '0'+num;
}else{
return num;
}
}
showClock();
setInterval(showClock,1000)
}