Last active
November 8, 2016 01:28
-
-
Save thomasmarren/59c2da734d0928a3019f05c268d0128a to your computer and use it in GitHub Desktop.
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
<!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