Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Created January 1, 2017 17:53
Show Gist options
  • Save DanyelMorales/7416dc69165b2f318bf7ca0089f6e96b to your computer and use it in GitHub Desktop.
Save DanyelMorales/7416dc69165b2f318bf7ca0089f6e96b to your computer and use it in GitHub Desktop.
Current UTC Live Time Clock
<div class="bigtime shadow rounded bgwgr"><span id="time" class="fontbig">00:00:00</span>
<script src="clock.js"></script>
<script src="clockinit.js"></script>
var tf='24h';
function pad(val) { return val > 9 ? val : "0" + val; }
function gettimestr(totalsec, tfr) {
var hours = parseInt(totalsec / 3600) % 24;
var minutes = parseInt(totalsec / 60) % 60;
var seconds = totalsec % 60;
if(tfr === '24h') {
return pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
}
else {
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
return hours + ':' + pad(minutes)+ ':' + pad(seconds) +' <small>' + ampm+'</small>';
}
}
// unit of time hrs or PM|AM
function setTf(tfr) {
tf = tfr;
}
// Current UTC time to timestamp
var date = new Date();
h = date.getUTCHours() * 60 * 60;
m = date.getUTCMinutes() * 60;
s = date.getUTCSeconds();
var sec = h + m + s;
// Starting our clock
setInterval(function () {
document.getElementById('time').innerHTML = gettimestr(++sec,tf);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment