我有记录用户付款的程序,用户可获得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
与其一起计算,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)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句