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

前端 未结 28 2199
自闭症患者
自闭症患者 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:12

    import * as moment from 'moment'
    var sleep = require('sleep-promise');
    
    (async function () {
        var t1 = new Date().getTime();
        await sleep(1000); 
        var t2 = new Date().getTime();
        var dur = moment.duration(t2-t1); 
        console.log(`${dur.hours()}h:${dur.minutes()}m:${dur.seconds()}s`);
    })();
    
    
    0h:0m:1s
    

提交回复
热议问题