我有一個(gè)像下面這樣的 C# 代碼用于日期時(shí)間處理,想知道如何修復(fù)它。//Value of effective date api_reqBody["effectiveDate"] = DateTime.Today.AddDays(2).ToString(Helper.DATE_FORMAT_API);//Value of Maturity date var effDate = Convert.ToDateTime(api_reqBody["effectiveDate"]);api_reqBody["updatedLoanAccount"]["maturityDate"] = new DateTime(effDate.Year + uServiceSupport.H300IORIL_MAXTERM_YEARS, effDate.Month, effDate.Day + 1).ToString(Helper.DATE_FORMAT_API); // Value of H300IORIL_MAXTERM_YEARS is 5 .對于上述代碼的日期時(shí)間處理,我收到了 ArgumentOutOfRangeException - 當(dāng)它今天在 29/05 運(yùn)行時(shí)。請參閱下面的消息如果我將生效日期更改為 AddDays(3) ,它會(huì)再次開始工作。但我想更可靠地修復(fù)它api_reqBody["effectiveDate"] = DateTime.Today.AddDays(3).ToString(Helper.DATE_FORMAT_API);
如何在 C# 中修復(fù)未來日期的 ArgumentOutOfRangeException
慕無忌1623718
2021-07-06 13:00:06