Convert Seconds to H:M:S in jQuery

Posted on September 29, 2019 at 4:50 pm

Simple function to convert seconds in H:M:S in jQuery:

function secondsTimeSpanToHMS(s){ var h = Math.floor(s/3600); s -= h*3600; var m = Math.floor(s/60); s -= m*60; return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s); }

You can use it like this:

var seconds = 148;
console.log(secondsTimeSpanToHMS(seconds));

Receive updates via email

Other Posts

Updated Posts