Private Sub Command1_Click() Dim strT As String Dim a() As String Dim i As Integer Dim time1 As Date Dim time2 As Date
strT = "00:01-01:00,16:01-17:00,22:01-23:00,23:01-23:59" a = Split(strT, ",")
For i = 0 To UBound(a) time1 = Split(a(i), "-")(0) & ":00" time2 = Split(a(i), "-")(1) & ":00" If Time > time1 And Time < time2 Then MsgBox "time in " & a(i) End If Next i
End Sub
Dim lngTime As Long lngTime = Hour(Time) * 60 + Minute(Time) Debug.Print Hour("00:15") * 60 + Minute("00:15") < lngTime And lngTime < Hour("01:00") * 60 + Minute("01:00")
从大到小比较,不用比上限:Dim strNow As StringstrNow = Format(Now(), "HH:nn")Select Case strNow Case Is > "23:00" MsgBox "23:01-24:00" Case Is > "22:00" MsgBox "22:01-23:00" '...... Case Is > "01:00" MsgBox "01:01-02:00" Case Else MsgBox "00:01-01:00" End Select
s=format(time,"hh:ss")...
Dim strT As String
Dim a() As String
Dim i As Integer
Dim time1 As Date
Dim time2 As Date
strT = "00:01-01:00,16:01-17:00,22:01-23:00,23:01-23:59"
a = Split(strT, ",")
For i = 0 To UBound(a)
time1 = Split(a(i), "-")(0) & ":00"
time2 = Split(a(i), "-")(1) & ":00"
If Time > time1 And Time < time2 Then
MsgBox "time in " & a(i)
End If
Next i
End Sub
lngTime = Hour(Time) * 60 + Minute(Time)
Debug.Print Hour("00:15") * 60 + Minute("00:15") < lngTime And lngTime < Hour("01:00") * 60 + Minute("01:00")
Case Is > "23:00"
MsgBox "23:01-24:00"
Case Is > "22:00"
MsgBox "22:01-23:00"
'......
Case Is > "01:00"
MsgBox "01:01-02:00"
Case Else
MsgBox "00:01-01:00"
End Select
if elseif
elseif
.....
这么复杂,俺们来个简单点的 Dim tmpdate As Date
tmpdate = Now
If Minute(tmpdate) < 1 Then
MsgBox "当前时间在" & Format(DateAdd("H", -1, tmpdate), "HH") & ":01" & "至" & Format(tmpdate, "HH") & ":00" & "时间内"
Else
MsgBox "当前时间在" & Format(tmpdate, "HH") & ":01" & "至" & Format(DateAdd("H", 1, tmpdate), "HH") & ":00" & "时间内"
End If
设置
DTPicker1.Format =dtpTime
或
DTPicker1.CustomFormat = "HH:mm:ss"
DTPicker1.Format = dtpCustom
Format:設為用戶定義dptCustom
CustomFormat:HH:mm:ss
即是時間控件了。
设置
DTPicker1.Format =dtpTime
或
DTPicker1.CustomFormat = "HH:mm:ss"
DTPicker1.Format = dtpCustom
或如下:Private Sub Command1_Click()
Dim iTime(23) As String
For i = 0 To 23
iTime(i) = Format(i, "00"":00-""") & Format(i + 1, "00"":00""")
Next
For i = 0 To 23
If Format(Hour(Now), "00") = Left(iTime(i), 2) Then
MsgBox Left(Time, 5) & "在" & iTime(i) & "区间"
Exit For
End If
Next
End Sub