我想将天数添加到当前日期,例如我想输入数字的天数,而不是我选择我想在当前日期添加的日期是指天,周和月,但是当我选择天或周或者它显示日期,但无法在当前日期添加它们
任何人都可以帮助我
任何人都可以帮助我
protected void TextBoxPredictDays_TextChanged(object sender,EventArgs e) { string selectPredictDays = DropDownList1.SelectedItem.Value; String Days1; int Result; Days1 = TextBoxPredictedClosing.ToString(); if (selectPredictDays == "Days") { Result = Convert.ToInt32(TextBoxPredictDays.Text) * 1; TextBoxPredictedClosing.Text = Result.ToString(); } else if (selectPredictDays == "Weeks") { Result = Convert.ToInt32(TextBoxPredictDays.Text) * 7; TextBoxPredictedClosing.Text = Result.ToString(); } else if (selectPredictDays == "Months") { Result = Convert.ToInt32(TextBoxPredictDays.Text) * 30; TextBoxPredictedClosing.Text = Result.ToString(); } }
这是我的设计代码
<asp:TextBox ID="TextBoxPredictDays" runat="server" ontextchanged="TextBoxPredictDays_TextChanged" Width="101px" Height="14px" ></asp:TextBox> <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>Days</asp:ListItem> <asp:ListItem>Weeks</asp:ListItem> <asp:ListItem>Months</asp:ListItem> </asp:DropDownList>
解决方法
DateTime.Now.AddDays(int) – 天数 DateTime.Now.AddDays(int * 7) – 持续数周 DateTime.Now.AddMonths(int) – 几个月