计算两个DateTime间的时间差(小时差、分钟差、秒钟差等)
private static int dateDiff(DateTime dtStart, DateTime dtEnd) { TimeSpan tsStart = new TimeSpan(dtStart.Ticks); TimeSpan tsEnd = new TimeSpan(dtEnd.Ticks); TimeSpan ts = tsEnd.Subtract(tsStart).Duration(); int dateDiffSecond = ts.Days * 24 * 60 * 60 + ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds; //两个时间的秒差 return dateDiffSecond; }