JSFiddle - React, Tailwind, and code Playground

by Arnaud

HTML

<span class="txt-capital spanDuree"></span> |
<div id="timespan">

</div>

<div id="dureeTrajet">118550</div>

JavaScript

Number.prototype.toHHMMSS = function() {
  var hours = Math.floor(this / 3600) < 10 ? ("00" + Math.floor(this / 3600)).slice(-2) : Math.floor(this / 3600);
  var minutes = ("00" + Math.floor((this % 3600) / 60)).slice(-2);
  var seconds = ("00" + (this % 3600) % 60).slice(-2);
  return hours + ":" + minutes ;
}

// Usage: [number variable].toHHMMSS();

// Here is a simple test
var totalseconds = $('#dureeTrajet').text();
document.getElementById("timespan").innerHTML = totalseconds.toHHMMSS();