Jquery计算时间戳之间的差值,可返回年,月,日,小时等
原创
©著作权归作者所有:来自51CTO博客作者wsw9284的原创作品,请联系作者获取转载授权,否则将追究法律责任
/**
* 计算时间戳之间的差值
* @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;
}
学习交流群:364976091