Obtain the time difference, in the format of year-month-day hour: minute: Second or year-month-day hour: minute: Second
The Code is as follows:
/*
* Time Difference obtained, in the format of year-month-day hour: minute: Second or year/month/day hour: minute: Second
* The year, month, and day are in full format, for example, 01:00:00
* Return accuracy: seconds, minutes, hours, days
*/
Function GetDateDiff (startTime, endTime, diffType ){
// Convert the time format of xxxx-xx to the format of xxxx/xx
StartTime = startTime. replace (/\-/g ,"/");
EndTime = endTime. replace (/\-/g ,"/");
// Converts the computing interval class characters to lowercase letters.
DiffType = diffType. toLowerCase ();
Var sTime = new Date (startTime); // start time
Var eTime = new Date (endTime); // End Time
// Number used as the Divisor
Var pNum = 1;
Switch (diffType ){
Case "second ":
Pnum= 1000;
Break;
Case "minute ":
Pnum= 1000*60;
Break;
Case "hour ":
Pnum= 1000*3600;
Break;
Case "day ":
PNum = 1000*3600*24;
Break;
Default:
Break;
}
Return parseInt (eTime. getTime ()-sTime. getTime ()/parseInt (pNum ));
}
The call method is also simple:
GetDateDiff ("00:00:00", "00:01:40", "day ")
This is the computing day
GetDateDiff ("00:00:00", "00:01:40", "seond") is calculated in seconds.