问题
convert years and months into days.first convert back to years and months and now want to convert back to days.code is like the one below
if len >366
len1 = cstr (math.floor(len/365))
len = len mod 365
len1 = len * 365
thanks in advance
回答1:
days = years * 365.25
years = days / 365.25
回答2:
DateTime.DaysInMonth Method
Dim July as integer = 7
' daysInJuly gets 31.
Dim daysInJuly as integer = System.DateTime.DaysInMonth(2001, July);
Then to get the Days In Year:
Private Function GetDaysInAYear(year As Integer) As Integer
Dim days As Integer = 0
Dim i As Integer = 1
While i <= 13
days += DateTime.DaysInMonth(year, i)
i++
End While
Return days
End Function
回答3:
To get Days in a year you can simply do this:
Dim year As Integer = 2012 ' Set year here
Dim totalDaysInYear As Integer = New Date(year, 12, 31).Subtract(New Date(year, 1, 1)).Days
OR: (easy to understand)
Dim year As Integer = 2012 ' Set year here
Dim d1 As New Date(year, 1, 1)
Dim d2 As New Date(year, 12, 31)
Dim totalDaysInYear As Integer = d2.Subtract(d1).Days
To get days In month:
Dim year As Integer = 2012
Dim DaysInMonth As Integer = Date.DaysInMonth(year, 11) ' Evaluates Nov 2012
来源:https://stackoverflow.com/questions/13130754/convert-years-and-months-into-days-in-vb-net