admin管理员组

文章数量:1399944

I wanted to check if momentjs is able to convert a given number of seconds to a ISO 8601 formatted duration string.

E.g. 1000 seconds will lead to PT16M40S.

I wanted to check if momentjs is able to convert a given number of seconds to a ISO 8601 formatted duration string.

E.g. 1000 seconds will lead to PT16M40S.

Share Improve this question edited Feb 13, 2019 at 12:06 Patrick 2,2453 gold badges23 silver badges36 bronze badges asked Nov 14, 2016 at 14:46 nitte93nitte93 1,8503 gold badges28 silver badges42 bronze badges 2
  • npmjs./package/moment-duration – Dan Wilson Commented Nov 14, 2016 at 14:52
  • using a library to replace one line of code is kind of crazy. – Paul Rooney Commented Sep 9, 2019 at 4:21
Add a ment  | 

1 Answer 1

Reset to default 11

You can use toISOString on the duration:

moment.duration(1000, 'seconds').toISOString() //"PT16M40S"

本文标签: javascriptConvert total seconds to ISO 8601 duration string with momentjsStack Overflow