//JS calculation two time difference //StartDate: Start time, EndDate: End Time (time format: 2018-5-18 11:51:40 string) functionCALDATEDIFFFN (StartDate, endDate) {//the number of milliseconds for the time difference varMillsecsdiff =NewDate (endDate). GetTime ()-NewDate (startdate). GetTime (); //calculate the difference in days varDaysdiff = Math.floor (Millsecsdiff/(24 * 3600 * 1000)); //calculate the number of hours varleave1 = millsecsdiff% (24 * 3600 * 1000);//number of milliseconds remaining after counting days varHoursdiff = Math.floor (leave1/(3600 * 1000)); //calculate the number of minutes difference varLeave2 = leave1% (3600 * 1000);//number of milliseconds remaining after hours of calculation varMinutesdiff = Math.floor (Leave2/(60 * 1000)); //calculate the number of seconds difference varLeave3 = leave2% (60 * 1000);//Count the number of milliseconds left after the number of minutes varSecondsdiff = Math.Round (leave3/1000); //return the results you need returnSecondsdiff; }
JS Calculation two time difference