Jquery计算时间戳之间的差值,可返回年,月,日,小时等
/** * 计算时间戳之间的差值 * @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; }
微信号:jamesworkshop 学习QQ群:364976091