How to use moment-duration-format in TypeScript?

前端 未结 4 1230
忘掉有多难
忘掉有多难 2021-02-19 06:00

I am using moment.js in my TypeScript (Ionic2/Angular2) project. Following on from this post, I now want to try out a plugin moment-duration-format

I have the npm packag

4条回答
  •  长发绾君心
    2021-02-19 06:06

    I was using the workaround here, but it now looks like the ype def has been fixed. Getting an update of the type def So I can do the following...

    import * as moment from 'moment';
    import 'moment-duration-format';
    
    let duration = moment.duration(decimalHours, 'hours') ;   
    let options : moment.DurationFormatSettings   = {
      forceLength : false,
      precision : 0,
      template : formatString,
      trim : false
    };
    let result  = duration.format(formatString, 0, options);
    

提交回复
热议问题