计算40天前的日期:

var temp = new Date();
console.log(temp);
var tempValue = temp.getTime() - 40 * 24* 60*60*1000;
var temp2 = new Date(tempValue );
console.log(temp2);