I have a sql query that returns customer wait time in seconds. The following javascript is used to convert seconds to HH:MM:SS, but does not work when the sum of wait time is greater than 24 hours. For example, if wait time is 600 seconds, it displays correctly as 00:10:00. However, if the wait time is 90600 seconds, it displays as 01:10:00 rather than 25:10:00. Any help is greatly appreciated.
if (format == 'secondsToHHMMSS') {
var dt = new Date();
var dtToday = new Date();
var dt = new Date(dtToday.getFullYear(), dtToday.getMonth(), dtToday.getDate(),0,0,0);
dt.setSeconds(num);
return add0(dt.getHours()) + ':' + add0(dt.getMinutes()) + ':' + add0(dt.getSeconds());
}
function secondsToHHMMSS (seconds) {
return (Math.floor(seconds / 3600)) + ":" + ("0" + Math.floor(seconds / 60) % 60).slice(-2) + ":" + ("0" + seconds % 60).slice(-2)
}
console.log(secondsToHHMMSS(600), secondsToHHMMSS(90600))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With