Skip to content

Instantly share code, notes, and snippets.

@SBachvarov
Last active November 30, 2016 19:05
Show Gist options
  • Save SBachvarov/197153b1a524ed6344577cd194ead3fc to your computer and use it in GitHub Desktop.
Save SBachvarov/197153b1a524ed6344577cd194ead3fc to your computer and use it in GitHub Desktop.
Real time changing clock with JavaScript
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('time').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
return h;
}
function checkTime(i) {
if (i <10) {i = "0" + i}
return i;
}
</script>
//In HTML
...
<div id="somid">Some content</div>
<script type="text/javascript">
oQuickReply.swap('somid');
</script>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment