How can I convert milliseconds to “hhmmss” format using javascript?

前端 未结 6 2174
花落未央
花落未央 2021-01-18 02:11

I am using javascript Date object trying to convert millisecond to how many hour, minute and second it is.

I have the currentTime in milliseconds

var         


        
6条回答
  •  醉酒成梦
    2021-01-18 02:47

    If you are confident that the period will always be less than a day you could use this one-liner:

    new Date(timeDiff).toISOString().slice(11,19)   // HH:MM:SS
    

    N.B. This will be wrong if timeDiff is greater than a day.

提交回复
热议问题