How to use format() on a moment.js duration?

前端 未结 28 2299
自闭症患者
自闭症患者 2020-11-27 04:34

Is there any way I can use the moment.js format method on duration objects? I can\'t find it anywhere in the docs and it doesn\'t seen to be an attribute on du

28条回答
  •  误落风尘
    2020-11-27 05:15

    // set up
    let start = moment("2018-05-16 12:00:00"); // some random moment in time (in ms)
    let end = moment("2018-05-16 12:22:00"); // some random moment after start (in ms)
    let diff = end.diff(start);
    
    // execution
    let f = moment.utc(diff).format("HH:mm:ss.SSS");
    alert(f);
    

    Have a look at the JSFiddle

提交回复
热议问题