Skip to content

Instantly share code, notes, and snippets.

@waynew
Created May 6, 2014 03:13
Show Gist options
  • Save waynew/51fe623397c90096a36f to your computer and use it in GitHub Desktop.
Save waynew/51fe623397c90096a36f to your computer and use it in GitHub Desktop.
Simplest clock ever
<?doctype html>
<html>
<body>
<meta name="viewport" content="width=100%">
<div id="clock" style="font-size: 18vw;" width="100%"></div>
</body>
<script>
function padTwo(n){
return ("00"+n).slice(-2);
}
function setTime(){
var clock_div = document.getElementById("clock");
var now = new Date();
clock_div.innerHTML = padTwo(now.getHours()%12) + ":" + padTwo(now.getMinutes()) + ":" + padTwo(now.getSeconds()) + (now.getHours()%12 == 0 ? " AM" : " PM");
setTimeout(setTime, 1000);
}
setTime();
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment