有没有,小时.分钟.秒的时间控件?如果没有的话,我们自定义时间段:00:01-01:00,01:01-02:00....22:01-23:00,23:01-24:00.
如何判断当前时间NOW()属于某个时间段?

解决方案 »

  1.   

    判断now()是否>时间段下限并且<时间段上限就可以了
      

  2.   

    比如时间00:15   怎么比较它在00:00-01:00 时间内
    s=format(time,"hh:ss")...
      

  3.   

    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
      

  4.   

    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")
      

  5.   

    从大到小比较,不用比上限: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
      

  6.   

    也可以用
    if elseif
    elseif
    .....
      

  7.   


    这么复杂,俺们来个简单点的    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
      

  8.   

    DTPicker控件就可以显示  小时.分钟.秒
    设置
         DTPicker1.Format =dtpTime 

        DTPicker1.CustomFormat = "HH:mm:ss"
        DTPicker1.Format = dtpCustom
      

  9.   

    如果是00:00-00:59这样的就更简单MsgBox "当前时间在" & Format(tmpdate, "HH") & ":00" & "至" & Format(tmpdate, "HH") & ":59" & "时间内"
      

  10.   

    DTPicker日期控件
    Format:設為用戶定義dptCustom
    CustomFormat:HH:mm:ss
    即是時間控件了。
      

  11.   

    DTPicker控件就可以显示  小时.分钟.秒
    设置
        DTPicker1.Format =dtpTime

        DTPicker1.CustomFormat = "HH:mm:ss"
        DTPicker1.Format = dtpCustom 
      

  12.   

    取time$的前两个字符转换成数值即可知!
      

  13.   

    DTPicker控件
    或如下: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