Moment.js 文档

减去 1.0.0+

moment().subtract(Number, String);
moment().subtract(Duration);
moment().subtract(Object);

通过减去时间来改变原始 moment。

这和 moment#add 完全一样,只是不是加了时间,而是减了时间。

moment().subtract(7, 'days');

2.8.0 版本之前,还支持 moment#subtract(String, Number) 语法。 它已被弃用,取而代之的是 moment#subtract(Number, String)

moment().subtract('seconds', 1); // Deprecated in 2.8.0
moment().subtract(1, 'seconds');

2.12.0 起,当天数和月数传递十进制值时,它们将四舍五入为最接近的整数。 周、季度和年转换为天或月,然后四舍五入为最接近的整数。

moment().subtract(1.5, 'months') == moment().subtract(2, 'months')
moment().subtract(.7, 'years') == moment().subtract(8, 'months') //.7*12 = 8.4, rounded to 8

请注意,为了使操作 moment.add(-.5, 'days') and moment.subtract(.5, 'days') 等效,-.5、-1.5、-2.5 等向下舍入。