Skip to content

Instantly share code, notes, and snippets.

@panphora
Created October 11, 2018 23:26
Show Gist options
  • Save panphora/4bb6e1ae87472d97df98371230d37f0e to your computer and use it in GitHub Desktop.
Save panphora/4bb6e1ae87472d97df98371230d37f0e to your computer and use it in GitHub Desktop.
function displayTimeLeft (endDate) {
var msUntilDate = endDate - (new Date).getTime();
var secs = Math.floor(msUntilDate / 1000) // total seconds until end date
, mins = Math.floor(secs / 60) // total minutes until end date
, hours = Math.floor(mins / 60) // total hours until end date
, days = Math.floor(hours / 24); // total days until end date
secs = secs % 60; // seconds remaining after dividing by 60 -- for display in countdown
mins = mins % 60; // minutes remaining after dividing by 60 -- for display in countdown
hours = hours % 24; // hours remaining after dividing by 24 -- for display in countdown
mins < 10 && (mins = "0" + mins);
secs < 10 && (secs = "0" + secs);
$("span.days").text(days);
$("span.hours").text(hours);
$("span.minutes").text(mins);
$("span.seconds").text(secs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment