Skip to content

Instantly share code, notes, and snippets.

@GertjanBrouwer
Created July 11, 2017 13:52
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 GertjanBrouwer/ef8999cc0295ce3bf7b4ba84a5e44cc7 to your computer and use it in GitHub Desktop.
Save GertjanBrouwer/ef8999cc0295ce3bf7b4ba84a5e44cc7 to your computer and use it in GitHub Desktop.
<html>
<head></head>
<body>
<p id="timer">
</p>
<style>
#timer{
font-size: 60px;
}
</style>
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous">
</script>
<script>
$(document).ready(function() {
var endTime = getDate(getMinutesUntilNextHour());
var x = setInterval(function() {
var now = new Date().getTime();
var distance = endTime - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer").innerHTML = "Nog " + days + " dagen " + hours + " uur "
+ minutes + " minuten en " + seconds + " seconden ";
if (distance < 0) {
clearInterval(x);
document.getElementById("timer").innerHTML = "Nieuwe kortingscode toegevoegd, herlaad de pagina!";
}
}, 1000);
});
function getMinutesUntilNextHour() {
return 60 - new Date().getMinutes();
}
function getDate(minutes) {
var ret = new Date();
return ret.setTime(ret.getTime() + minutes*60000);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment