Skip to content

Instantly share code, notes, and snippets.

@dsincl12
Created June 16, 2016 11:06
Show Gist options
  • Save dsincl12/60d04251bca4b04c41a597e8280d0aa8 to your computer and use it in GitHub Desktop.
Save dsincl12/60d04251bca4b04c41a597e8280d0aa8 to your computer and use it in GitHub Desktop.
var calculateElapsedTime = function (startTime, endTime) {
var milliseconds = endTime - startTime;
var seconds = Math.round(milliseconds / 1000);
var minutes = Math.floor(seconds / 60);
var hours = minutes > 59 ? Math.floor(minutes / 60) : 0;
if (minutes > 0) {
seconds -= minutes * 60;
}
if (minutes > 59) {
minutes -= hours * 60;
}
return {
hours: hours,
minutes: minutes,
seconds: seconds
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment