I wrote it myself, it’s just applicable, not very good, it should still be optimized. Record it yourself first. Stop talking nonsense, it’s best to post the code directly:
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 "hour":
divNum = 1000 * 3600; divNum = 1000 * 3600 * 24;
break ;
default:
break;
}
return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
}
The calling method is also very simple:
GetDateDiff("2010-10-11 00:00:00", "2010-10-11 00:01:40", "day")