Skip to content

Instantly share code, notes, and snippets.

@vankasteelj
Last active February 2, 2024 11:08
Show Gist options
  • Save vankasteelj/74ab7793133f4b257ea3 to your computer and use it in GitHub Desktop.
Save vankasteelj/74ab7793133f4b257ea3 to your computer and use it in GitHub Desktop.
Javascript - Seconds to Time (hh:mm:ss,ms) -> sec2time(593.685038) becomes 00:09:53,685
function sec2time(timeInSeconds) {
var pad = function(num, size) { return ('000' + num).slice(size * -1); },
time = parseFloat(timeInSeconds).toFixed(3),
hours = Math.floor(time / 60 / 60),
minutes = Math.floor(time / 60) % 60,
seconds = Math.floor(time - minutes * 60),
milliseconds = time.slice(-3);
return pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2) + ',' + pad(milliseconds, 3);
}
@peorthyr
Copy link

thanks

@saijeevanballa
Copy link

thanks

@iamir4g
Copy link

iamir4g commented Apr 12, 2020

thanks

@gusblacknails
Copy link

Thanks!

@GiovaniFerraroTrivelli
Copy link

Thanks! 👍

@MirzaBaig715
Copy link

Thanks!

@rhodler
Copy link

rhodler commented Oct 17, 2020

Merci ! 😃

@Natsumi-sama
Copy link

tyvm

@m-sobhanian
Copy link

thanks

@Taaseen71
Copy link

appreciate It

@oussama-kaifouf
Copy link

Thank you so much

@sivaprabug
Copy link

I have time like this 17:49:58.606 in chrome console , How to convert to unix time stamp ?

@noszone
Copy link

noszone commented May 24, 2021

Working good, thanks.

@kirpachov
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment