Skip to content

Instantly share code, notes, and snippets.

@hirejohnsalcedo
Created June 2, 2017 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirejohnsalcedo/1ab3509c55a19b2a9d5b9dc4027a1b00 to your computer and use it in GitHub Desktop.
Save hirejohnsalcedo/1ab3509c55a19b2a9d5b9dc4027a1b00 to your computer and use it in GitHub Desktop.
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