本文介绍了日期时间在C#中添加天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在某些日期添加天。我有一个code是这样的:
I want to add days in some date. I have a code like this:
DateTime endDate = Convert.ToDateTime(this.txtStartDate.Text); Int64 addedDays = Convert.ToInt64(txtDaysSupp.Text); endDate.AddDays(addedDays); DateTime end = endDate; this.txtEndDate.Text = end.ToShortDateString();但是,这code不工作,天不会添加!我在做什么愚蠢的错误?
But this code is not working, days are not added! What the stupid mistake I'm doing?
推荐答案日期时间是不变的。这意味着你不能改变它的状态,并有一个操作的结果分配给一个变量。
DateTime is immutable. That means you cannot change it's state and have to assign the result of an operation to a variable.
endDate = endDate.AddDays(addedDays);更多推荐
日期时间在C#中添加天
发布评论