Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert seconds to HH:MM:SS format in JavaScript.
new Date(seconds * 1000).toISOString().substr(11, 8)
@raskri
Copy link

raskri commented Nov 23, 2016

NICE one

@floydback
Copy link

floydback commented May 24, 2017

super!

@sidvishnoi
Copy link

sidvishnoi commented Jan 7, 2018

limitation: the duration cannot be more than 24 hours (it'll overflow)

@webix
Copy link

webix commented Feb 21, 2018

nice!

@youneshenniwrites
Copy link

youneshenniwrites commented Jan 22, 2019

Phenomenal dude!

@shaunjanssens
Copy link

shaunjanssens commented Mar 4, 2019

Nice, thanks!

@MTGPROD
Copy link

MTGPROD commented Aug 29, 2019

This is incredible, thanks!

@Sanusihassan
Copy link

Sanusihassan commented Apr 1, 2020

great

@shahab570
Copy link

shahab570 commented Jul 30, 2020

Why multiply seconds into 1000? can anyone explain?

@martinbean
Copy link
Author

martinbean commented Jul 30, 2020

@McJoe21
Copy link

McJoe21 commented Dec 14, 2020

What about for software that doesn't support script file (eg automate)

@selfnatiq
Copy link

selfnatiq commented Apr 16, 2021

Failed: secToTime(359999) - Expected: '99:59:59', instead got: '03:59:59'

@martinbean
Copy link
Author

martinbean commented Apr 18, 2021

Failed: secToTime(359999) - Expected: '99:59:59', instead got: '03:59:59'

Overflow. Should only be used with seconds value of less that 24 hours (86400).

@lausch4ngriff-radio
Copy link

lausch4ngriff-radio commented May 4, 2021

awesome one-liner!

@NintenZone
Copy link

NintenZone commented May 16, 2021

Came looking for an answer, and I suppose I found it 😂

@sidelux
Copy link

sidelux commented Jul 8, 2021

Thanks, works well on Chrome but fails in Safari (14.1.1).

@martinbean
Copy link
Author

martinbean commented Jul 8, 2021

Thanks, works well on Chrome but fails in Safari (14.1.1).

@sidelux It works fine in Safari 14.1.1. It’s just basic JavaScript:

Screenshot 2021-07-08 at 14 22 42

@sidelux
Copy link

sidelux commented Jul 8, 2021

Thanks, works well on Chrome but fails in Safari (14.1.1).

@sidelux It works fine in Safari 14.1.1. It’s just basic JavaScript:

Screenshot 2021-07-08 at 14 22 42

Yes, it was another error. Sorry.

@mohsinraza
Copy link

mohsinraza commented Feb 4, 2022

great

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