为了账号安全,请及时绑定邮箱和手机立即绑定

我正在处理 Javascript 日期,我坚持将日期添加 7 天

我正在处理 Javascript 日期,我坚持将日期添加 7 天

精慕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 日期,我坚持在这个日期上添加 7 天
查看完整描述

1 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

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)


查看完整回答
反对 回复 2023-03-03
  • 1 回答
  • 0 关注
  • 152 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号