當前位置:文思屋>社會工作>電腦培訓>

怎麼使用Javascript獲取距今n天前的日期

文思屋 人氣:2.39W

複製程式碼 程式碼如下:

怎麼使用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);

}