當前位置:才華齋>設計>網頁設計>

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

網頁設計 閱讀(2.95W)

複製程式碼 程式碼如下:

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

}