Skip to content

Instantly share code, notes, and snippets.

@ariona
Last active Dec 14, 2017
Embed
What would you like to do?
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