标签:date() var 时间 alt gettime null diff cond else
1 // 计算时间长度开始:如果结束时间是现在 2 function getTotalTime(startTime, endTime) { 3 if (startTime != null && startTime != ‘‘ && startTime != "") { 4 var startTim = new Date(startTime.replace(/-/g, "/")); 5 // var endTime = new Date(); 6 if (endTime != null && endTime != undefined && endTime != "") { 7 endTime = new Date(endTime.replace(/-/g, "/")); 8 } else { 9 endTime = new Date(); 10 } 11 var dateDiff = endTime.getTime() - startTim.getTime(); 12 var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); 13 var leave1 = dateDiff % (24 * 3600 * 1000); 14 var hours = Math.floor(leave1 / (3600 * 1000)); 15 var leave2 = leave1 % (3600 * 1000); 16 var minutes = Math.floor(leave2 / (60 * 1000)); 17 var leave3 = leave2 % (60 * 1000); 18 var seconds = Math.round(leave3 / 1000); 19 return dayDiff + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒"; 20 } else { 21 return ""; 22 } 23 }
标签:date() var 时间 alt gettime null diff cond else
原文地址:https://www.cnblogs.com/yangguoe/p/9267425.html