Created
November 22, 2016 09:48
-
-
Save alash3al/11be5ec8591a30bb1e4aa30ecd677f03 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
/** | |
* Get the difference between two dates in detailed info | |
* | |
* @param float|int d1 | |
* @param float|int d2 | |
* | |
* @return Object | |
*/ | |
function timeDiffBetween(d1, d2) { | |
result = { | |
diff: 0, | |
reminder: 0, | |
days: 0, | |
hours: 0, | |
minutes: 0, | |
seconds: 0 | |
} | |
helpers = { | |
second: 1, | |
minute: 1 * 60, | |
hour: 1 * 60 * 60, | |
day: 1 * 60 * 60 * 24, | |
} | |
result.diff = (d1 - d2) / 1000 | |
result.days = parseInt(result.diff / helpers.day) | |
result.reminder = result.diff % helpers.day | |
result.hours = parseInt(result.reminder / helpers.hour) | |
result.reminder = result.reminder % helpers.hour | |
result.minutes = parseInt(result.reminder / helpers.minute) | |
result.reminder = result.reminder % helpers.minute | |
result.seconds = parseInt(result.reminder) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment