Skip to content

Instantly share code, notes, and snippets.

@gregogalante
Created June 13, 2018 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregogalante/5914eebec0372e8e83b1cd5796d21b61 to your computer and use it in GitHub Desktop.
Save gregogalante/5914eebec0372e8e83b1cd5796d21b61 to your computer and use it in GitHub Desktop.
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