Created
July 11, 2012 14:35
-
-
Save rtorr/3090775 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
//not very pretty | |
var dateFuture = new Date(2012,5,2,0,00,00); | |
function GetCount(ddate,iid){ | |
var dateNow = new Date(), | |
amount = ddate.getTime() - dateNow.getTime(), | |
days, | |
hours, | |
mins, | |
secs, | |
out; | |
if(amount < 0){ | |
document.getElementById(iid).innerHTML="Now!"; | |
}else{ | |
days=0; | |
hours=0; | |
mins=0; | |
secs=0; | |
out=""; | |
amount = Math.floor(amount/1000); | |
days=Math.floor(amount/86400); | |
amount=amount%86400; | |
hours=Math.floor(amount/3600); | |
amount=amount%3600; | |
mins=Math.floor(amount/60); | |
amount=amount%60; | |
secs=Math.floor(amount); | |
if(days !== 0){ | |
out += days +" "+((days===1)?"day":"days")+", "; | |
} | |
if(hours !== 0){ | |
out += hours +" "+((hours===1)?"hour":"hours")+", "; | |
} | |
out += mins +" "+((mins===1)?"min":"mins")+", "; | |
out += secs +" "+((secs===1)?"sec":"secs")+", "; | |
out = out.substr(0,out.length-2); | |
document.getElementById(iid).innerHTML=out; | |
setTimeout(function(){ | |
GetCount(ddate,iid); | |
}, 1000); | |
} | |
} | |
window.onload=function(){ | |
GetCount(dateFuture, 'countbox1'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment