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

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

    How to correctly use moment.js durations? | Use moment.duration() in code

    First you need to import moment and moment-duration-format.

    import moment from 'moment';
    import 'moment-duration-format';
    

    Then, use duration function. Let us apply the above example: 28800 = 8 am.

    moment.duration(28800, "seconds").format("h:mm a");
    

提交回复
热议问题