Created
June 2, 2017 20:12
-
-
Save hirejohnsalcedo/1ab3509c55a19b2a9d5b9dc4027a1b00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const clock = document.getElementById("clock"); | |
function leadZeroFormat(i) { | |
if (i<10) { | |
i = "0" + i; | |
} | |
return i; | |
} | |
function startClock() { | |
const dateObject = new Date(); | |
let h = dateObject.getHours(); | |
let m = dateObject.getMinutes(); | |
let s = dateObject.getSeconds(); | |
h = leadZeroFormat(h); | |
m = leadZeroFormat(m); | |
s = leadZeroFormat(s); | |
clock.innerHTML = `${h}:${m}:${s}` | |
setTimeout(startClock, 500); | |
} | |
startClock(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment