round up/ round down a momentjs moment to nearest minute

后端 未结 10 1444
一整个雨季
一整个雨季 2020-12-05 01:47

How do you round up/ round down a momentjs moment to nearest minute?

I have checked the docs, but there doesn\'t appear to be a method for this.

Note that I

10条回答
  •  春和景丽
    2020-12-05 02:11

    I was searching for this same question and found a better solution: Use the third parameter in diff() function:

    moment("2019-05-02 17:10:20").diff("2019-05-02 17:09:30","minutes",true)

    By setting third parameter to true, you get the raw value as response that you can round by yourself using Math.round()

    See JSFiddle: https://jsfiddle.net/2wqs4o0v/3/

提交回复
热议问题