The following small series will bring you a js computing time difference code, including computing, day, hour, minute, and second ]. I think this is quite good. Now I will share it with you and give you a reference for var begintime_ms = Date. parse (new Date (begintime. replace (/-/g, "/"); // begintime is the start time.
Var endtime_ms = Date. parse (new Date (endtime. replace (/-/g, "/"); // endtime is the end time
The result is the number of milliseconds. The time can be determined based on the number of milliseconds.
Of course, you can calculate the number of days or hours of difference based on the number of milliseconds.
-------------------------------
The preceding figure shows the user input time in milliseconds.
Var date1 = new Date (); // 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 ")
The above js computing time difference code, including computing, day, hour, minute, and second, is all the content that xiaobian shares with you. I hope to give you a reference, I also hope that you will support your feet.