Created
January 1, 2017 17:53
-
-
Save DanyelMorales/7416dc69165b2f318bf7ca0089f6e96b to your computer and use it in GitHub Desktop.
Current UTC Live Time Clock
This file contains 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 class="bigtime shadow rounded bgwgr"><span id="time" class="fontbig">00:00:00</span> | |
<script src="clock.js"></script> | |
<script src="clockinit.js"></script> |
This file contains 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
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; | |
} |
This file contains 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
// 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