Skip to content

Instantly share code, notes, and snippets.

@thomasmarren
Last active November 8, 2016 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasmarren/59c2da734d0928a3019f05c268d0128a to your computer and use it in GitHub Desktop.
Save thomasmarren/59c2da734d0928a3019f05c268d0128a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="clockdiv"></div>
</body>
<script>
var deadline = 'December 25 2016 18:30:00 UTC -0400';
function timeRemaining(deadline){
var time = Date.parse(deadline) - Date.parse(new Date());
var seconds = Math.floor( (time/1000) % 60 );
var minutes = Math.floor( (time/1000/60) % 60 );
var hours = Math.floor( (time/(1000*60*60)) % 24 );
var days = Math.floor( time/(1000*60*60*24) );
return {
'total': time,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function buildClock(id, deadline){
var clock = document.getElementById(id);
var timeInterval = setInterval(function(){
var time = timeRemaining(deadline);
clock.innerHTML = time.days + " : " + time.hours + " : " + time.minutes + " : " + time.seconds;
if(time.total<=0){
clearInterval(timeInterval);
}
},1000);
}
buildClock('clockdiv', deadline);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment