//计算时间差 function GetDateDiff(startTime, endTime, diffType) { //将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式 startTime = startTime.replace(/-/g, "/"); endTime = endTime.replace(/-/g, "/"); //将计算间隔类性字符转换为小写 diffType = diffType.toLowerCase(); var sTime = new Date(startTime); //开始时间 var eTime = new Date(endTime); //结束时间 //作为除数的数字 var divNum = 1; switch (diffType) { case "second": divNum = 1000; break; case "minute": divNum = 1000 * 60; break; case "hour": divNum = 1000 * 60 * 60; break; case "day": divNum = 1000 * 60 * 60 * 24; break; default: break; } return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));