In fact, JavaScript calculates the time difference in a very simple way, if it is the default date () type, the direct subtraction is the difference between milliseconds
var D1 = new Date (' 2016/03/28 10:17:22 '), var d2 = new Date (' 2016/03/28 11:17:22 '), Console.log (parseint (D2-D1));//Two time difference Number of milliseconds Console.log (parseint (D2-D1)/1000),//Two time difference in seconds Console.log (parseint (D2-D1)/1000/60);//two time difference in minutes console.log ( parseint (D2-D1)/1000/60);//Two hours of difference between time
If you do not get the date type, but rather the string format "2016-03-28 10:27:00", then you need to convert the string to a date type first.
var t1 = "2016-03-28 10:27:00"; var D1 = T1.replace (/\-/g, "/"); var date1 = new Date (D1);
The above-mentioned date1 is a date type. Can be calculated, as long as a simple encapsulation, you can assemble any event type conversion function.
For example: The input string gets the number of seconds difference:
<!doctype html> JavaScript calculates two time difference