Skip to content
Advertisement

How to convert seconds to HH:mm:ss in moment.js

How can I convert seconds to HH:mm:ss?

At the moment I am using the function below

JavaScript

This works on chrome but in firefox for 12 seconds I get 01:00:12 I would like to use moment.js for cross browser compatibility

I tried this but does not work

JavaScript

What am I doing wrong?

EDIT

I managed to find a solution without moment.js which is as follow

JavaScript

Still curious on how I can do it in moment.js

Advertisement

Answer

From this post I would try this to avoid leap issues

JavaScript

I did not run jsPerf, but I would think this is faster than creating new date objects a million times

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement