當前位置:學者齋 >

設計製作 >網頁設計 >

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

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

}

  • 文章版權屬於文章作者所有,轉載請註明 https://xuezhezhai.com/zh-tw/sjzz/sjzz/4vrx36.html