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

前端 未结 6 2175
花落未央
花落未央 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:45

    The difference in time is in milliseconds: Get time difference between two dates in seconds

    to get the difference you have to use math.floor() http://www.w3schools.com/jsref/jsref_floor.asp

    var secDiff = Math.floor(timeDiff / 1000); //in s
    var minDiff = Math.floor(timeDiff / 60 / 1000); //in minutes
    var hDiff = Math.floor(timeDiff / 3600 / 1000); //in hours
    

提交回复
热议问题