1:第一种方式:
string firsttime = "20140226120201"; string secondtime = "20140225115401"; 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=1,如果是一年,那么span.Days=365<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 );
原文:http://www.cnblogs.com/lcal/p/3569827.html