我有以下VB.NET代码: Dim Date1 As New DateTime(2010,5,6)Dim Date2 As New DateTime(2009,10,12)Dim NumOfMonths = 0 ' This is where I am stumped 我想要做的是找出两个日期之间有多少个月.任何帮助,将不胜感激. 这是
Dim Date1 As New DateTime(2010,5,6) Dim Date2 As New DateTime(2009,10,12) Dim NumOfMonths = 0 ' This is where I am stumped
我想要做的是找出两个日期之间有多少个月.任何帮助,将不胜感激.
这是您可以使用的方法:Public Shared Function MonthDifference(ByVal first As DateTime, ByVal second As DateTime) As Integer Return Math.Abs((first.Month - second.Month) + 12 * (first.Year - second.Year)) End Function
像这样:
Dim Date1 As New DateTime(2010,5,6) Dim Date2 As New DateTime(2009,10,12) Dim NumOfMonths = MonthDifference(Date1, Date2)