Convert milliseconds to hours and minutes using Momentjs

前端 未结 11 2478
滥情空心
滥情空心 2020-12-09 15:00

I am new to Momentjs. I am trying to use it to convert milliseconds to hours and minutes. Below, x is milliseconds

x = 433276000
var y = moment.duration(x, \         


        
11条回答
  •  难免孤独
    2020-12-09 15:28

    Momentjs itself doesn't support duration, in order to do so, we need a plugin moment-duration-format

    To use this plugin follow these steps (for React-js)

    import moment from 'moment';
    import momentDurationFormatSetup from "moment-duration-format";
    
    var time = moment.duration(value,unit).format('hh:mm:ss',{trim:false})
    

    Note: I have used {trim: false} as extra parameter so that it doesn't trim out extra 0's in the beginning. You can omit it if you want "11:30" instead of "00:11:30".

提交回复
热议问题