日期:2014-05-19  浏览次数:20764 次

请问取两个日期变量的值应该怎么取?
比如说2007-1-1减去2006-1-1要等于1年要怎么取?

------解决方案--------------------
DateTime A = DateTime.Parse( "2007-1-1 ");
DateTime B = DateTime.Parse( "2006-1-1 ");
TimeSpan T = new TimeSpan(A.Ticks - B.Ticks);

Text = (T.TotalDays / 365).ToString();

------解决方案--------------------
DateTime A = DateTime.Parse( "2007-1-1 ");
DateTime B = DateTime.Parse( "2006-1-1 ");
TimeSpan T = new TimeSpan(A.Ticks - B.Ticks);

再取 T 里面的年属性就行了
------解决方案--------------------
DateTime A = DateTime.Parse( "2007-1-1 ");
DateTime B = DateTime.Parse( "2006-1-1 ");
int i = A.Year - B.Year;