1:第一种方式:
string firsttime = ""; string secondtime = ""; DateTime firstDateTemp = DateTime.ParseExact(firsttime, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true)); DateTime secondDateTemp = DateTime.ParseExact(secondtime, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true)); TimeSpan span = firstDateTemp.Subtract(secondDateTemp); 然后,如果相差一天,那么span.Days=,如果是一年,那么span.Days=<br> span.Hours, span.Minutes就不举例了
2:第二种方式:
DateTime onetime = DateTime.Parse("2014-2-26 05:32:22"); DateTime twotime = DateTime.Parse("2014-2-26 05:31:22"); TimeSpan span = onetime .Subtract(twotime );