VB 时间段决断问题

来源:百度知道 编辑:UC知道 时间:2024/09/26 20:08:45
如何决断一个时间在某个时间段里,如:第一个时间段20:00:00-第二天早上10:00:00,第二个时间段10:00:01至19:59:59如何决断时间23:00:00这个时间在第一时段还是第二时段.

先说不考虑时间短跨日的。
把起始时间和终止时间都转化成小数:
hh:mm:ss
t=(ss/60+mm)/60+hh)/24
分别的tb、te
再把
时刻同样转化(t),
if t>tb and t<te then
就可以了。

如果,时间段跨日,即tb>te
那么就应该用:
if t>tb or t<te then

就这么简单。

Option Explicit

Private Sub Command1_Click()
Dim x As Date
x = "23:00:00"
If x > "10:00:01" And x < "19:59:59" Then MsgBox x & "在第二个时间段" Else MsgBox x & "在第一个时间段"
End Sub