How to convert time milliseconds to hours, min, sec format in JavaScript?

后端 未结 16 2397
渐次进展
渐次进展 2020-11-29 02:28

I have the time as milliseconds, but I want the time after conversion like 00:00:00.

Ex: In milliseconds=86400000. I want how many hours in that millise

16条回答
  •  感动是毒
    2020-11-29 03:10

    The above snippets don't work for cases with more than 1 day (They are simply ignored).

    For this you can use:

    function convertMS(ms) {
        var d, h, m, s;
        s = Math.floor(ms / 1000);
        m = Math.floor(s / 60);
        s = s % 60;
        h = Math.floor(m / 60);
        m = m % 60;
        d = Math.floor(h / 24);
        h = h % 24;
        h += d * 24;
        return h + ':' + m + ':' + s;
    }
    

    Thanks to https://gist.github.com/remino/1563878

提交回复
热议问题