如果 time2 大于 9 小时到时间 1,则为 true



我正在为进出时间编写 VB.NET 代码。我的问题是当time2大于 9 小时time1时,我希望在这种情况下进行真实的陈述。

tat.Text = myreader.Item("Status").ToString
abs = myreader.Item("Time_In").ToString
abs1 = myreader.Item("Time_In").ToString
EndTime = TimeOfDay.ToString("h:mm:ss tt")
StartTime = TimeOfDay.ToString("h:mm:ss tt")
'  Main.oras.Text = StartTime
gtg2 = abs
gtg3 = gtg2.AddHours(9)
gtg4 = abs1

If gtg3 > gtg4 Then
   Label32.BackColor = Color.Red
End If

试试这个:

Dim dt1 = #1/4/2019 8:00#
Dim dt2 = #1/4/2019 20:00#
If dt2 - dt1 > TimeSpan.FromHours(9) Then
    MsgBox("Time is more than 9 hours")
Else
    MsgBox("Time is less than 9 hours")
End If

如果结束时间从开始时间开始超过 9 小时,我创建了这个函数:

Private Function GreaterThan9Hours(ByVal StartTime As DateTime, ByVal EndTime As DateTime) As Boolean
    If EndTime - StartTime > TimeSpan.FromHours(9) Then
        Return True
    Else
        Return False
    End If
End Function

相关内容

最新更新