Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created January 24, 2014 02:18
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 walterdavis/8590960 to your computer and use it in GitHub Desktop.
Save walterdavis/8590960 to your computer and use it in GitHub Desktop.
var d = new Date('2014-01-30T19:19:26.224Z');
var t = new Template($('counter').innerHTML);
function tick(){
var time = {days_0: 0, days_1: 0, hours_0: 0, hours_1: 0, mins_0: 0, mins_1: 0, secs_0: 0, secs_1: 0};
var secs = Math.floor((d.getTime() - new Date().getTime()) / 1000);
if(secs > 0){
var days = Math.floor(secs / 86400);
time['days_0'] = (days.toString().length == 1) ? 0 : days.toString().slice(0,1);
time['days_1'] = days.toString().slice(-1);
secs -= days * 86400;
var hours = Math.floor(secs / 3600);
time['hours_0'] = (hours.toString().length == 1) ? 0 : hours.toString().slice(0,1);
time['hours_1'] = hours.toString().slice(-1);
secs -= hours * 3600;
var mins = Math.floor(secs / 60);
time['mins_0'] = (mins.toString().length == 1) ? 0 : mins.toString().slice(0,1);
time['mins_1'] = mins.toString().slice(-1);
secs -= mins * 60;
time['secs_0'] = (secs.toString().length == 1) ? 0 : secs.toString().slice(0,1);
time['secs_1'] = secs.toString().slice(-1);
}else{
for(key in time){
time[key] = 0;
}
}
$('counter').update(t.evaluate(time));
}
tick();
setInterval(tick, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment