我正在查看一些报告,应该显示为2/1/2009 - 2/28/2009,但实际上显示的是2/1/2009 - 3/1/2009。我已经把这个错误缩小到了这份代码,有什么建议吗?
Function GetMonthLastDate(ByVal sDateTime As DateTime)
Try
Dim strArrMonth() As String = {"", "31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"}
Dim days As Integer
If sDateTime.Month = 2 Then
If sDateTime.Year Mod 400 = 0 Then Return sDateTime.AddDays(28)
If sDateTime.Year Mod 100 = 0 Then Return sDateTime.AddDays(27)
If sDateTime.Year Mod 4 = 0 Then Return sDateTime.AddDays(28)
End If
days = strArrMonth(sDateTime.Month)
Return Format(sDateTime.AddDays(days - 1), "MM/dd/yyyy")
Catch ex As Exception
Response.Write("<script>alert( " & ex.Message & " );</script>")
End Try
End Function