C#利用TimeSpan计算两个时间之间的时间差
传入两个时间参数即可得到准确的时间差
public static string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = ""; TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); TimeSpan ts = (TimeSpan)(ts2 - ts1); if (Convert.ToInt32(ts.Days.ToString()) < 0) dateDiff = "<font color=red>已经过期</font>"; else dateDiff = ts.Days.ToString()+"天"; return dateDiff; }