日期时间在C#中添加天

编程入门 行业动态 更新时间:2024-10-24 03:26:00
本文介绍了日期时间在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#中添加天

本文发布于:2023-11-09 22:58:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573668.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!