Created
April 5, 2012 16:01
-
-
Save obstschale/2312158 to your computer and use it in GitHub Desktop.
Countdown to a date
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
var dateFuture; | |
var dateNow; | |
var updateInterval; | |
/** updat every second **/ | |
function updateCount(){ | |
dateNow = new Date(); //grab current date | |
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates | |
delete dateNow; | |
// time is already past | |
if(amount <= 0){ | |
finishCountdown(); | |
} | |
// date is still good | |
else{ | |
days=0;hours=0;mins=0;secs=0;out=""; | |
amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs | |
days=Math.floor(amount/86400);//days | |
amount=amount%86400; | |
hours=Math.floor(amount/3600);//hours | |
amount=amount%3600; | |
mins=Math.floor(amount/60);//minutes | |
amount=amount%60; | |
secs=Math.floor(amount);//seconds | |
//update view | |
/*$("#days").html( days ); | |
$("#hours").html( hours ); | |
$("#minutes").html( mins ); | |
$("#seconds").html( secs );*/ | |
$("#counter").html( days+" TAGE "+hours+" STD. "+mins+" MIN." ); | |
} | |
} | |
/** when the countdown has been finished **/ | |
function finishCountdown(){ | |
clearInterval(updateInterval); | |
$('#countdown').hide(); | |
$('#finished').show(); | |
} | |
/** start the countdown **/ | |
function startCountdown(yyyy,mm,dd,h,m,s){ | |
dateFuture = new Date(yyyy,mm-1,dd,h,m,s); | |
updateCount(); | |
updateInterval = setInterval("updateCount()", 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment