日期:2014-05-20  浏览次数:21148 次

ASP.NET(C#)中两日期相减,如何得到相差的月份数?
ASP.NET(C#)中两日期相减,如何得到相差的月份数?

------解决方案--------------------
C# code
DateTime startDate = DateTime.Parse("2008-1-1");
DateTime endDate = DateTime.Parse("2010-10-31");
int totalMonth = endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month;

------解决方案--------------------
C# code

C# codeDateTime startDate = DateTime.Parse("2008-1-1");
DateTime endDate = DateTime.Parse("2010-10-31");
int totalMonth = endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month;

------解决方案--------------------
C# code
C# codeDateTime startDate = DateTime.Parse("2008-1-1");
DateTime endDate = DateTime.Parse("2010-10-31");
int totalMonth = endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month;