ts中根据一个日期获取n天前后的日期或时间戳

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/friend_ship/article/details/78878611

第一种:获取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();








猜你喜欢

转载自blog.csdn.net/friend_ship/article/details/78878611