Created
June 13, 2018 12:44
-
-
Save gregogalante/5914eebec0372e8e83b1cd5796d21b61 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 timeBetweenDates (dateTo, dateFrom) { | |
// get total seconds between the times | |
let delta = Math.abs(date_future - date_now) / 1000 | |
// calculate (and subtract) whole days | |
let days = Math.floor(delta / 86400) | |
delta -= days * 86400 | |
// calculate (and subtract) whole hours | |
let hours = Math.floor(delta / 3600) % 24 | |
delta -= hours * 3600 | |
// calculate (and subtract) whole minutes | |
let minutes = Math.floor(delta / 60) % 60 | |
delta -= minutes * 60 | |
// what's left is seconds | |
let seconds = delta % 60 | |
return { | |
days: days, | |
hours: hours, | |
minutes: minutes, | |
seconds: seconds | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment