JS中获得指定日期前或后几天对应的日期

var d = new Date();
d.setDate(d.getDate() - 2);
console.log(d.toString());

// First of month
var c = new Date(2017,1,1); // 1 Feb -> 30 Jan
c.setDate(c.getDate() - 2);
console.log(c.toString());

// First of year
var b = new Date(2018,0,1); // 1 Jan -> 30 Dec
b.setDate(b.getDate() - 2);
console.log(b.toString());
posted @ 2017-06-14 10:26  安果果  阅读(5576)  评论(0编辑  收藏  举报