Created
March 16, 2017 14:37
-
-
Save tux255/720f18386ecee4cf451953e1af87e164 to your computer and use it in GitHub Desktop.
Display current time with seconds
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
<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