C#中Datetime类型数据如何加减日期?

https://zhidao.baidu.com/question/546884030.html

第一种
DateTime time1 =new DateTime(1982,4,24,14,23,06);
DateTime time2 =new DateTime(1982,1,21,8,16,32);

TimeSpan ts= time2.Subtract(time1);
string timespan = "相差:"
+ts.Days.ToString()+"天"
+ts.Hours.ToString()+"小时"
+ts.Minutes.ToString()+"分钟"
+ts.Seconds.ToString()+"秒";
第二种:
DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(-7);
TimeSpan ts = dt1 - dt2; //TimeSpan 是一个 时间差
int days = ts.Days; //dt1和dt2相差多少天

第三种 DateTime.Add系列
System.DateTime today = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan(36, 0, 0, 0);
System.DateTime answer = today.Add(duration);
outputBlock.Text += String.Format("{0:dddd}", answer) + " ";

DateTime dt2 = DateTime.Now.AddDays(-7); 当前日期前7天
DateTime dt2 = DateTime.Now.AddDays(7); 当前日期后7天

其他如 DateTime.AddSeconds 等等,可参考 AddDays使用。