Skip to content

Instantly share code, notes, and snippets.

@tux255
Created March 16, 2017 14:37
Show Gist options
  • Save tux255/720f18386ecee4cf451953e1af87e164 to your computer and use it in GitHub Desktop.
Save tux255/720f18386ecee4cf451953e1af87e164 to your computer and use it in GitHub Desktop.
Display current time with seconds
<div id="time"></div>
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
t = setTimeout(function () {
startTime()
}, 500);
}
startTime();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment