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 milliseconds, and the time can be judged based on the size of milliseconds.
Of course, according to the number of milliseconds, you can find the difference of days or hours, etc. according to their difference.
--------------------------------------------------------------------------------------------------------------------------------
The above is the number of milliseconds to obtain the user input time
var date1=new Date(); //Start time
var date2=new Date(); //End time
var date3=date2.getTime()-date1.getTime() //The number of milliseconds of the time difference
--------------------------------------------------------------------------------------------------------------------------------
//Calculate the number of days of 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 counting the number of days
var hours=Math.floor(leave1/(3600*1000))
//Calculate the number of minutes of phase difference
var leave2=leave1%(3600*1000) //The number of milliseconds remaining after calculating the number of hours
var minutes=Math.floor(leave2/(60*1000))
//Calculate the phase difference seconds
var leave3=leave2%(60*1000) //The number of milliseconds remaining after counting the number of minutes
var seconds=Math.round(leave3/1000)
alert(" difference"+days+"days"+hours+"hours+" minutes+" minutes"+seconds+" seconds")
The above js calculation time difference code [including calculation, day, time, minute, and second] is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.