我想知道如何计算两个日期之间的月数。有什么方法可以用C#计算吗?
Eg1. Date1 = "2011/11/01"
Date2 = "2012/02/01"
Result. Numbers of Month =3
Eg2. Date1 = "2012/01/31"
Date2 = "2012/02/01"
Result. Numbers of Month =1
Eg3. Date1 = "2012/01/01"
Date2 = "2012/02/28"
Result. Numbers of Month =1
最佳答案
这将给出月份之间的差异:
int months = (Date2.Year - Date1.Year) * 12 + Date2.Month - Date1.Month;
关于c# - C# 如何计算两个日期之间的月数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829732/