<span style="white-space:pre"> </span> string a="2016-04-07 12:12:12";
DateTime time_a = DateTime.Parse(a);
string b = "2016-03-06 13:13:13";
DateTime time_b = DateTime.Parse(b);
TimeSpan ts = time_a.Subtract(time_b);
int day = ts.Days;
int hour = ts.Hours;
int minutes = ts.Minutes;
int second = ts.Seconds;
Console.WriteLine("day" + day); //day 31
Console.WriteLine("hour" + hour); //hour 22
Console.WriteLine("minutes" + minutes); //minutes 58
Console.WriteLine("second" + second); //second 59
C#中两个日期时间之间的时间间隔
本文转载:CSDN博客