/** * 计算时间戳之间的差值 * @param startTime 开始时间戳 * @param endTime 结束时间戳 * @param type 返回指定类型差值(year, month, day, hour, minute, second) */ function DateDiff(startTime, endTime, type) { var timeDiff = endTime - startTime switch (type) { case "year": return Math.floor(timeDiff / 86400 / 365); break; case "month": return Math.floor(timeDiff / 86400 / 30); break; case "day": return Math.floor(timeDiff / 86400); break; case "hour": return Math.floor(timeDiff / 3600); break; case "minute": return Math.floor(timeDiff / 60); break; case "second": return timeDiff % 60; break; }