Skip to content

Instantly share code, notes, and snippets.

@aamnah
Created October 28, 2015 14:07
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 aamnah/030daa57dc4af0040ad0 to your computer and use it in GitHub Desktop.
Save aamnah/030daa57dc4af0040ad0 to your computer and use it in GitHub Desktop.
Realtime JavaScript clock
<div id="time"></div>
(function () {
function checkTime(i) {
return (i < 10) ? "0" + i : i; // add a zero in front of numbers<10
}
function startTime() {
var today = new Date(),
h = checkTime(today.getHours()),
m = checkTime(today.getMinutes()),
s = checkTime(today.getSeconds());
document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
t = setTimeout(function () { // set Refresh rate. setTimeout() calls a function or executes a code after a specified delay
startTime()
}, 1000); // 1000ms = 1s. refresh clock every second
}
startTime();
})();
@aamnah
Copy link
Author

aamnah commented Oct 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment