Clock function that updates every second
A Pen by Francesco dAloisio on CodePen.
<div id="clock"></div> | |
<div id="utc"></div> | |
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet"> |
function clock(){ | |
var today = new Date; | |
// var hours = today.getHours(); | |
// var minutes = today.getMinutes(); | |
// var seconds = today.getSeconds(); | |
// if (hours<10){ | |
// hours = "0" + hours; | |
// } | |
// if (minutes<10){ | |
// minutes = "0" + minutes; | |
// } | |
// else { | |
// minutes = minutes; | |
// } | |
// if (seconds<10){ | |
// seconds = "0" + seconds; | |
// } | |
// else { | |
// seconds = seconds; | |
// } | |
// document.getElementById("clock").innerHTML = (hours + ":" + minutes + ":" + seconds); | |
var utc_time = today.toUTCString(); | |
document.getElementById("utc").innerHTML = (utc_time); | |
} | |
setInterval('clock()', 1000); |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
body { | |
background: #333; | |
color: white; | |
} | |
#clock,#utc { | |
text-align: center; | |
margin-top: 10%; | |
font-size: 4em; | |
font-family: 'Lato', sans-serif; | |
} |
Clock function that updates every second
A Pen by Francesco dAloisio on CodePen.