// Date subtraction in JAVASCRIPT is very troublesome. Now there are ready-made implementation methods, which can be used after copying.
// Call this method (main method)
Function dateDiff (date1, date2 ){
Var type1 = typeof date1, type2 = typeof date2;
If (type1 = string)
Date1 = stringToTime (date1 );
Else if (date1.getTime)
Date1 = date1.getTime ();
If (type2 = string)
Date2 = stringToTime (date2 );
Else if (date2.getTime)
Date2 = date2.getTime ();
Return (date1-date2)/1000; // The result is a second.
}
// The method required to convert a string to Time (dateDiff)
Function stringToTime (string ){
Var f = string. split (, 2 );
Var d = (f [0]? F [0]:). split (-, 3 );
Var t = (f [1]? F [1]:). split (:, 3 );
Return (new Date (
ParseInt (d [0], 10) | null,
(ParseInt (d [1], 10) | 1)-1,
ParseInt (d [2], 10) | null,
ParseInt (t [0], 10) | null,
ParseInt (t [1], 10) | null,
ParseInt (t [2], 10) | null
). GetTime ();
}
// Call dateDiff ("19:00:00", "18:00:00 ")
Returns the second.