function timeDiff(startTime,endTime){
//下面两行是针对日期格式为2017-08-01 18:56:38做的替换 需要的格式为2017/08/28 04:56:38
startTime = new Date(startTime.replace(/-/g, "/"));
endTime = new Date(endTime.replace(/-/g, "/"));
//两个时间差的总毫秒
let dateDiff = startTime.getTime() - endTime.getTime()
//天差
let dayDiff = Math.floor(dateDiff/(24*3600*100))
//时差
let hours = Math.floor((dateDiff%(24*3600*1000))/(1000*3600))
//分差
let mins = Math.floor((dateDiff%(24*3600*1000))%(1000*3600)/(60*1000))
//秒差
let secs = Math.floor((dateDiff%(24*3600*1000))%(1000*3600)%(60*1000)/1000)
return (dayDiff + '天' + hours + '小时' + mins + '分' + secs + '秒')
}
js求两个时间差
最新推荐文章于 2024-07-17 15:26:15 发布