Created
October 11, 2018 23:26
-
-
Save panphora/4bb6e1ae87472d97df98371230d37f0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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