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 do not want a string rounded to the nearest minute, I want a moment
returned (or modified in place, either is fine). I prefer not to have to convert to a string, and the convert back too.
Thanks.
As requested, here is some code:
var now = new moment(new Date());
if (now.seconds() > 0) {
now.add('minutes', -1);
}
now.seconds(0);
as you can see, I have managed to manually round down the moment here, but it seems rather hacky. Just after a more elegant way of accomplishing this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…