荟萃馆

位置:首页 > 设计 > 网页设计

怎么使用Javascript获取距今n天前的日期

复制代码 代码如下:

怎么使用Javascript获取距今n天前的日期

function Test(day) {

var today = new Date();

var beforMilliseconds = ime() - 1000 * 3600 * 24 * day;

var beforday = new Date();

ime(beforMilliseconds);

var strYear = ullYear();

var strDay = ate();

var strMonth = onth() + 1;

if (strMonth < 10) {

strMonth = "0" + strMonth;

}

var strYesterday = strYear + "-" + strMonth + "-" + strDay;

alert(strYesterday);

}