The following small series will bring you an implementation code for js time difference. I think it is quite good. I will share it with you now. I would also like to give you a reference. Let's take a look at var date1 = new Date (); // the start time.
Var date2 = new Date (); // End Time
Var date3 = date2.getTime ()-date1.getTime () // time difference in milliseconds
// Calculate the number of days for difference
Var days = Math. floor (date3/(24*3600*1000 ))
// Calculate the number of hours
Var leave1 = date3 % (24*3600*1000) // The number of milliseconds remaining after the number of computing days
Var hours = Math. floor (leave1/(3600*1000 ))
// Calculate the number of minutes of difference
Var leave2 = leave1 % (3600*1000) // The number of milliseconds remaining after the computing hours
Var minutes = Math. floor (leave2/(60*1000 ))
// Calculate the time difference in seconds
Var leave3 = leave2 % (60*1000) // The number of milliseconds remaining after the number of minutes is calculated
Var seconds = Math. round (leave3/1000)
Alert ("difference" + days + "days" + hours + "hours" + minutes + "minutes" + seconds + "seconds ")
Math. floor (Math. abs (k1-k2)/1000/60/60/24/0.5 +); // time difference rounding
Document. write ("two decimal places:" + a. toFixed (2) +"
Four decimal places "+ a. toFixed (4 ));
The implementation code of the above js time difference is all the content shared by the editor. I hope it can be used as a reference for you and also as a reference for your support.