亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為現在日期增加12個月

為現在日期增加12個月

慕容森 2021-05-06 14:32:59
嗨,我想加上12個月,并減去當前日期的1天。例子 :valStartDate:2018-01-20預期日期:2019-01-19我嘗試下面的代碼,但出現錯誤“ getFullYear()不允許使用的函數”this.endDate =this.valStartDate.getFullYear()+1+'-'+this.valStartDate.getMonth()+'-'+(this.valStartDate.getDate()-1);
查看完整描述

3 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

確保給定的開始日期是日期而不是字符串。


var startDate = new Date(2018, 0, 20);

var startDatePlus12Months = new Date(startDate.setMonth(startDate.getMonth() + 12));

var expectedDate = new Date(startDatePlus12Months.getFullYear(), startDatePlus12Months.getMonth(), startDatePlus12Months.getDate() - 1);



查看完整回答
反對 回復 2021-05-13
?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

this.endDate = new Date(this.endDate); // <= maybe you get a string date...

this.endDate.setMonth(this.endDate.getMonth() + 12);

this.endDate.setDate(this.endDate.getDate() - 1);

如果要從服務器或以前的Json格式獲取日期,則可能需要將其從轉換string為Datefirst :this.endDate = new Date(this.endDate);??磥磉@是您的情況。


查看完整回答
反對 回復 2021-05-13
  • 3 回答
  • 0 關注
  • 446 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號