Skip to content

Instantly share code, notes, and snippets.

@eduardolundgren
Created October 12, 2012 15:21
Show Gist options
  • Save eduardolundgren/3879727 to your computer and use it in GitHub Desktop.
Save eduardolundgren/3879727 to your computer and use it in GitHub Desktop.
var SECOND = 1000,
MINUTES = 60*SECOND,
HOURS = 60*MINUTES,
DAY = 24*HOURS;
var targetDate = new Date( Date.parse('Thu, 17 Oct 2012 18:00:00 GMT+0200') );
var diff = ( targetDate.getTime() - Date.now() );
var days = Math.floor(diff / DAY),
hours = Math.floor((diff - days*DAY) / HOURS),
minutes = Math.floor((diff - days*DAY - hours*HOURS) / MINUTES),
seconds = Math.floor((diff - days*DAY - hours*HOURS - minutes*MINUTES) / SECOND);
console.log(days, hours, minutes, seconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment