1. 程式人生 > >ts中根據一個日期獲取n天前後的日期或時間戳

ts中根據一個日期獲取n天前後的日期或時間戳

第一種:獲取n天前後的日期

curDate: Date;

this.curDate = new Date();

//n天前的日期

this.curDate.setDate(this.curDate.getDate()-n);


// n天后的日期

this.curDate.setDate(this.curDate.getDate()+n);




第二種:獲取n天前後的日期轉換為時間戳

curDate: any;

this.curDate = new Date();

//n天前的日期時間戳

this.curDate.setDate(this.curDate.getDate()-n);

this.curDate = moment(this.curDate).unix();


//n天后的日期時間戳

this.curDate.setDate(this.curDate.getDate()+n);

this.curDate = moment(this.curDate).unix();