(int)(time1 - time2).TotalHours
time1、time2为两个日期
diff()
用TimeSpan类来实现
DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddHours(-3).AddDays(-1);
TimeSpan ts = dt1.Subtract(dt2);
double hours = ts.TotalHours;