Moment.js moment().subtract() 方法

moment 对时间的调整可以参考下面的代码:

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

下面的代码示例显示了相关的操作。

const moment = require('moment'); 

let momentA = moment(); 
console.log( 
	"Current MomentA is:", momentA.toString() 
); 

momentA.subtract(5, 'hours'); 
console.log( 
	"Current MomentA is:", momentA.toString() 
); 

momentA.subtract(15, 'minutes'); 
console.log( 
	"Current MomentA is:", momentA.toString()); 

momentA.subtract(2, 'days'); 
console.log( 
	"Current MomentA is:", momentA.toString() 
); 

momentA.subtract(2, 'months'); 
console.log( 
	"Current MomentA is:", momentA.toString() 
); 

momentA.subtract(10, 'years'); 
console.log( 
	"Current MomentA is:", momentA.toString() 
);

JavaScript 对时间的操作,通常使用 moment 对象来进行操作。

其实就是使用 subtract 方法。