用str(time)即可生成形如10:15:32的字符串,然后就好处理了

解决方案 »

  1.   

    '这个程序是转换为秒的。要是要变成分就自己乘个60,这个程序有个小BUG,即开始时间和结束时间必须在同一天。要修正这个BUG就得记录开始日期和结束日期!
    Private Sub Command1_Click()
        Dim time_start As String, time_end As String, splittime As String
        time_start = "06:00"    '开始时间
        time_end = "08:00"      '结束时间
        splittime = "07:00"     '分隔时间
        MsgBox "开始于" & time_start & vbCrLf & "结束于" & time_end & vbCrLf & "在" & splittime & "前有" & GetTimer(splittime) - GetTimer(time_start) & "秒" & vbCrLf & "在" & splittime & "后有" & GetTimer(time_end) - GetTimer(splittime) & "秒"
    End Sub'此函数的功能是把一个"06:00:00"形的字符转化为他从零点开始的秒数21600
    Private Function GetTimer(tt As String) As Single
        Dim i As Integer, temp As Single
        Dim t() As String
        t = Split(tt, ":")
        temp = 0
        For i = 0 To UBound(t)
            temp = temp + Val(t(i)) * (60 ^ (2 - i))
        Next
        GetTimer = temp
    End Function