我有以下代码...如果在textbox1中将显示为10:10:00 AM并且在textbox2中时间将在4小时时间段自动显示为06:10:01 AM ..如果textbox2时间将是06:10:01 AM,则MSg框将显示“您无法注册到此站点,因为4小时时段将结束”
Dim tb1Val As DateTime = #8:20:20 AM#
Dim beforeVal As New TimeSpan(3, 59, 59)
Dim tb2Val As DateTime = tb1Val.AddSeconds(-beforeVal.TotalSeconds)
请记住,在textbox1中,时间将是任意.....并且textbox2将根据textbox1自动生成时间,以便在textbox1和textbox2之间保持4小时的时间段
答案 0 :(得分:0)
像
这样的东西Dim tb1Date As Date = Date.Parse(TextBox1.Text) ''# make sure that TextBox1 has a valid date input
Dim tb2Date As Date = Date.Parse(TextBox2.Text) ''# make sure that TextBox2 has a valid date input
Dim Span As TimeSpan = tb2Date - tb1Date ''# get the timespan between the two dates (later date first)
If (Math.Floor(Span.TotalHours) < 4 Then
''# You can not registered to this site because the 4 hours time slot will be over
Else
''# You're good to go!
End If