Skip to content

Instantly share code, notes, and snippets.

@mikekavouras
Last active August 29, 2015 14:02
Show Gist options
  • Save mikekavouras/35b9957f3d2a04513355 to your computer and use it in GitHub Desktop.
Save mikekavouras/35b9957f3d2a04513355 to your computer and use it in GitHub Desktop.
var d = new Date();
d.setMonth(6);
d.setDate(11);
d.setYear(2014);
d.setHours(23);
d.setMinutes(59);
d.setSeconds(59);
function pad(num) {
return num < 10 ? "0" + num : num;
}
setInterval(function() {
var now = new Date();
var diff = d.getTime() - now.getTime();
var seconds = diff / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24
days = pad(Math.floor(days));
hours = pad(Math.floor(hours % 24));
minutes = pad(Math.floor(minutes % 60));
hours = pad(Math.floor(hours % 60));
seconds = pad(Math.floor(seconds % 60));
console.log(days + ":" + hours + ":" + minutes + ":" + seconds);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment