Skip to content

Instantly share code, notes, and snippets.

@ariona
Last active December 14, 2017 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariona/bc10197b10954753cc5703608a7e3b32 to your computer and use it in GitHub Desktop.
Save ariona/bc10197b10954753cc5703608a7e3b32 to your computer and use it in GitHub Desktop.
Formatting seconds times to HH:MM:SS

Convert Seconds time format into HH:MM:SS.

If the seconds is less than an hour then the format returned will be MM:SS

formatTime(seconds) {
return seconds > 3600
?
[
parseInt(seconds / 60 / 60),
parseInt(seconds / 60 % 60),
parseInt(seconds % 60)
].join(":").replace(/\b(\d)\b/g, "0$1")
:
[
parseInt(seconds / 60 % 60),
parseInt(seconds % 60)
].join(":").replace(/\b(\d)\b/g, "0$1")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment