我创建了VB.net项目。我有两个文本框和两个按钮
我的约束是,如果我单击button2(Duedate),而不是将textbox1日期30天添加到textbox2中。 怎么做到这一点?
我希望结果像下面的那样
If I give textbox1 = 12/12/2009
than
I click Duedate: textbox2.text =11/1/2010
有可能吗? 提前谢谢。
答案 0 :(得分:3)
像这样:
Dim d As Date
If DateTime.TryParse(textbox1.Text, d) Then
textbox2.Text = d.AddDays(30).ToShortDateString()
End If
答案 1 :(得分:1)
您的按钮文字应该是:
If IsDate(TextBox1.Text) Then
Dim newdate As Date = CDate(TextBox1.Text)
newdate = newdate.AddDays(30)
Dim myDateFormat As String = "dd/MM/yyyy" //or whatever
DueDateTExtbox2.Text = newdate.ToString(myDateFormat)
End If
答案 2 :(得分:0)
'test data
Dim dStr As String = "25/12/2009"
Dim d, d30 As DateTime
Dim invC As New System.Globalization.CultureInfo("") 'invariant culture
If DateTime.TryParseExact(dStr, "dd/M/yyyy", _
invC, _
Globalization.DateTimeStyles.AllowWhiteSpaces _
Or Globalization.DateTimeStyles.AssumeLocal, d) Then
d30 = d.AddDays(30)
End If