JSFiddle - React, Tailwind, and code Playground

by Arnaud

HTML

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

<div id="timespan"></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();


var totalSeconds = document.getElementById("dureeTrajet").innerHTML; 
document.getElementById("timespan").innerHTML = totalSeconds;