Get time between dates

/** * Get time between dates * @param {String} past Past date * @param {String} future Future date * @returns {Array} Time between dates (milliseconds, seconds, minutes, hours, days) */ function getTimeBetweenDates(past, future) { const pastAsDate = new Date(past), futureAsDate = new Date(future); const milliseconds = pastAsDate - futureAsDate, seconds = Math.round(milliseconds / 1000), minutes = Math.round(seconds / 60), hours = Math.floor(minutes / 60), days = Math.floor(hours / 24); return [milliseconds, seconds, minutes, hours, days]; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.