我有记录用户付款的程序,用户可以获得30天的手机信用,我需要做的是在datetimepiker选择1-1-2015我希望在这一天之后获得30天所以价值将是1 -2-2015。 我怎么能这样做?
Dim Day = DateTimePicker1.Value.Day
Dim Month = DateTimePicker1.Value.Month
Dim Year = DateTimePicker1.Value.Year
Dim d As Integer = Day + 30
Dim m As Integer
Dim dd As Integer
Dim mm As Integer
If d > 30 Then
dd = d - 30
m = Month + 1
End If
If m > 12 Then
mm = Month - 12
Year = Year + 1
TextBox1.Text = dd & "-" & mm & "-" & Year
Else
TextBox1.Text = dd & "-" & m & "-" & Year
End If
答案 0 :(得分:2)
不应使用Integers
进行计算,而应使用DateTime.AddDays
:
Dim dt As Date = DateTimePicker1.Value
Dim thirtyDaysAfter As Date = dt.AddDays(30)
TextBox1.Text = thirtyDaysAfter.ToString("dd-MM-yyyy")
如果你想要下个月,你可以使用dt.AddMonths(1)
。