精慕HU
2023-03-03 10:04:43
var date = new Date(); var first_date = new Date(date); //Make a copy of the date we want the first and last days from first_date.setUTCDate(1); //Set the day as the first of the month var firstDay = first_date.toJSON().substring(0, 10); console.log(firstDay)我正在處理 Javascript 日期,我堅(jiān)持在這個(gè)日期上添加 7 天
1 回答

哈士奇WWW
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
var date = new Date();
var first_date = new Date(date); //Make a copy of the date we want the first and last days from
first_date.setUTCDate(1); //Set the day as the first of the month
var firstDay = first_date.toJSON().substring(0, 10);
var resultDate = new Date();
resultDate.setDate(first_date.getDate() + 7);
var resultDay = resultDate.toJSON().substring(0, 10);
console.log("First day: " + firstDay)
console.log("7 days from specific day: " + resultDay)
添加回答
舉報(bào)
0/150
提交
取消