Retrieve
GetDateDiff(start, end, "day")
/*
* Get the time difference, the time format is year-month-day hour:minute:second or year/month/day hour:minute:second
* Among them, year, month and day are in full format, for example : 2010-10-12 01:00:00
* The return precision is: seconds, minutes, hours, days
*/
function GetDateDiff(startTime, endTime, diffType) {
//will The time format of xxxx-xx-xx is converted to the format of xxxx/xx/xx
startTime = startTime.replace(/-/g, "/");
endTime = endTime.replace(/-/g , "/");
//Convert calculation interval characters to lowercase
diffType = diffType.toLowerCase();
var sTime = new Date(startTime); //Start time
var eTime = new Date(endTime); //End time
//Number as divisor
var divNum = 1;
switch (diffType) {
case "second":
divNum = 1000;
break;
case "minute":
divNum = 1000 * 60; break;
case "day":
divNum = 1000 * 3600 * 24;
break;
default:
break;
}
return parseInt((eTime.getTime () - sTime.getTime()) / parseInt(divNum)); //17jquery.com
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn