Is there a name for date/time interval format like “1h10m”

前端 未结 2 1182
情歌与酒
情歌与酒 2020-12-06 08:26

It\'s commonplace even outside of software to communicate time or date intervals in a truncated manner. For example: 1h10m translates to \"One hour and ten minu

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 09:18

    You can use moment: http://momentjs.com/docs/#/durations/

    moment.duration(100); // 100 milliseconds
    moment.duration(60000).humanize(); // a minute
    

    Read more in the above linked docs. And to get all unit values you may want to use the ISO8601 Format:

    moment.duration(1, 'd').toISOString() // "P1D"
    

    For example, "P3Y6M4DT12H30M5S" represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds". Read more directly under http://momentjs.com/docs/#/durations/as-iso-string/

提交回复
热议问题