javascript parse time (minutes:seconds) from milliseconds

后端 未结 4 2084
再見小時候
再見小時候 2020-12-16 16:57

How to parse a given amount of milliseconds (e.g. 125230.41294642858) into a time format like: minutes:seconds?

4条回答
  •  难免孤独
    2020-12-16 17:31

    Even though moment.js does not provide such functionality, if you come here and you are already using moment.js, try this:

    function getFormattedMs(ms) {
      var duration = moment.duration(ms);
      return moment.utc(duration.asMilliseconds()).format("mm:ss");
    }
    

    This workaround in moment was introduced in this Issue.

提交回复
热议问题