Last active
March 25, 2022 14:33
-
-
Save hebertcisco/646883125ff05f359ecb452efcc77163 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 getTimeRemaining(endtime) { | |
let time = Date.parse(endtime) - Date.parse(new Date().toDateString()); | |
const THOUSAND = 1000; | |
const HOURS_IN_DAY = 24; | |
const MINUTES_IN_HOUR = 60; | |
const SECONDS_IN_MINUTE = MINUTES_IN_HOUR; | |
let seconds = Math.floor(time / THOUSAND % SECONDS_IN_MINUTE); | |
let minutes = Math.floor( | |
time / THOUSAND / SECONDS_IN_MINUTE % MINUTES_IN_HOUR | |
); | |
let hours = Math.floor( | |
time / (THOUSAND * SECONDS_IN_MINUTE * MINUTES_IN_HOUR) % HOURS_IN_DAY | |
); | |
let days = Math.floor( | |
time / (THOUSAND * SECONDS_IN_MINUTE * MINUTES_IN_HOUR * HOURS_IN_DAY) | |
); | |
return { | |
total: time, | |
days: days, | |
hours: hours, | |
minutes: minutes, | |
seconds: seconds | |
}; | |
} | |
const falta = getTimeRemaining('2022-05-08 00:00:00'); | |
console.log(falta); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment