How can I convert milliseconds to "hhmmss" format using javascript?

const secDiff = timeDiff / 1000; //in s
const minDiff = timeDiff / 60 / 1000; //in minutes
const hDiff = timeDiff / 3600 / 1000; //in hours  

updated

function msToHMS( ms ) {
    // 1- Convert to seconds:
    let seconds = ms / 1000;
    // 2- Extract hours:
    const hours = parseInt( seconds / 3600 ); // 3,600 seconds in 1 hour
    seconds = seconds % 3600; // seconds remaining after extracting hours
    // 3- Extract minutes:
    const minutes = parseInt( seconds / 60 ); // 60 seconds in 1 minute
    // 4- Keep only seconds not extracted to minutes:
    seconds = seconds % 60;
    alert( hours+":"+minutes+":"+seconds);
}

const timespan = 2568370873; 
msToHMS( timespan );  

Demo


If you are confident that the period will always be less than a day you could use this one-liner:

new Date(timeDiff).toISOString().slice(11,19)   // HH:MM:SS

N.B. This will be wrong if timeDiff is greater than a day.