Created
April 25, 2017 02:32
-
-
Save axetroy/64bd521766688d927be948a38b97af55 to your computer and use it in GitHub Desktop.
计算两个时间点的时间差
This file contains 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 diffTime(time1) { | |
return function(time2) { | |
let seconds = Math.abs(time1 - time2) / 1000; | |
const days = Math.floor(seconds / (3600 * 24)); | |
seconds = seconds - days * 3600 * 24; | |
const hours = Math.floor(seconds / 3600); | |
seconds = seconds - hours * 3600; | |
const minutes = Math.floor(seconds / 60); | |
seconds = seconds - minutes * 60; | |
return { | |
days, | |
hours, | |
minutes, | |
seconds: parseInt(seconds) | |
}; | |
}; | |
} |
Author
axetroy
commented
Apr 25, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment