Django-Learn/djlearn/pages/static/js/base.js

20 lines
483 B
JavaScript

document.addEventListener('DOMContentLoaded', (event) => {
clock();
})
function clock() {
const today = new Date();
let h = today.getHours();
let m = today.getMinutes();
let s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('clock').innerHTML = h + ":" + m + ":" + s;
setTimeout(clock, 1000);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}