两个日期之间的月份不同

时间:2016-02-19 10:52:59

标签: vb.net

我如何才能获得正确的格式。

假设我有21.03.2010的约会对象                 日期为21.05.2011

我的日期差异应该返回类似

的内容
Months / Years
    3/2010
    4/2010
    5/2010
    ...
    12/2010
    1/2011
    ...
    5/2011

1 个答案:

答案 0 :(得分:0)

这应该让你前进:

Private Sub Button50_Click(sender As Object, e As EventArgs) Handles Button50.Click

    printDateRange(New Date(2010, 3, 21), New Date(2011, 5, 21))

End Sub

Private Sub printDateRange(startDate As Date, endDate As Date)

    Dim months As Integer = DateDiff(DateInterval.Month, startDate, endDate)

    For parser As Integer = 0 To months
        Dim newdate As Date = startDate.AddMonths(parser)
        Debug.Print(String.Format("{0}/{1}", newdate.Month, newdate.Year))
    Next

End Sub

您仍然需要添加所有验证和错误处理等