For a more thorough explanation of the current solution, additional context or detailed information would be beneficial. Regarding the query about "hours/minutes/seconds," you can refer to the following details or explore further at milliseconds to time in javascript.
Moreover,
You may opt for subtraction as a method – such as end - start, according to the sample code below.
var startTimestamp = 1488021704531;
var endTimestamp = 1488022516572;
document.write(endTimestamp - startTimestamp + '<br/>');
This will provide an output of 812041
- representing milliseconds.
If you wish to convert these milliseconds into the conventional format of hh:mm:ss.ms
, you can utilize the example code below – also accessible on jsfiddle.
var startTimestamp = 1488021704531;
var endTimestamp = 1488022516572;
document.write(endTimestamp - startTimestamp + '<br/>');
document.write(millisecondsToHoursMinutesSeconds(endTimestamp - startTimestamp));
document.write('<hr/>');
function millisecondsToHoursMinutesSeconds(ms) {
var milliseconds = parseInt((ms%1000)/100)
, seconds = parseInt((ms/1000)%60)
, minutes = parseInt((ms/(1000*60))%60)
, hours = parseInt((ms/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
Alternatively, peruse other solutions related to this issue in the question posted here: milliseconds to time in javascript