Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.