1:第一种方式:
string firstDate = "20140226120201"; string secondDate = "20140225115401"; DateTime firstDateTemp = DateTime.ParseExact(firstDate, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true)); DateTime secondDateTemp = DateTime.ParseExact(secondDate, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true)); TimeSpan span = firstDateTemp.Subtract(secondDateTemp); 然后,如果相差一天,那么span.Days=1,如果是一年,那么span.Days=365
span.Hours, span.Minutes就不举例了
2:第二种方式:
DateTime t1 = DateTime.Parse("2007-1-1 05:32:22"); DateTime t2 = DateTime.Parse("2007-1-1 05:31:22"); TimeSpan span = t1.Subtract(t2);