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 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 calculating the number of days
var hours=Math.floor(leave1/(3600*1000))
//Calculate the difference in minutes
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 difference in seconds
var leave3=leave2%(60*1000) //The number of milliseconds remaining after calculating the minutes
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 points:"+a.toFixed(2)+"
Four decimal points"+a.toFixed(4));
The above JS time difference implementation code is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.