Adding a TimeSpan to a given DateTime

后端 未结 8 1012
生来不讨喜
生来不讨喜 2020-12-17 08:36

I just want to add 1 day to a DateTime. So I wrote:

 DateTime date = new DateTime(2010, 4, 29, 10, 25, 00);
 TimeSpan t = new TimeSpan(1, 0, 0,          


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-17 09:01

    A DateTime is immutable, but the Add and Subtract functions return new DateTimes for you to use.

    DateTime tomorrow = DateTime.Now.AddDays(1);
    

提交回复
热议问题