计算两段时间的

发表于:2007-05-25来源:作者:点击数: 标签:#35745#31639#20004#27573#2
在写程序时,很多时候都要用到两个给定时间的时间差,所以特地把这个函数写出来以便以后可以方便的调用: function GetDoTime(Time1, Time2) Dim stime If Time1 Time2 Then stime = Time1 Time1 = Time2 Time2 = stime End If secondvalue = DateDiff("s", Tim

在写程序时,很多时候都要用到两个给定时间的时间差,所以特地把这个函数写出来以便以后可以方便的调用:

function GetDoTime(Time1, Time2)

Dim stime
    If Time1 > Time2 Then
       stime = Time1
       Time1 = Time2
       Time2 = stime
    End If
    secondvalue = DateDiff("s", Time1, Time2)
    dayvalue = DateDiff("d", Time1, Time2)
    hourvalue = Fix((secondvalue - dayvalue * 24 * 3600) / 3600)
    If hourvalue < 0 Then dayvalue = dayvalue - 1: hourvalue = 24 + hourvalue
    minitevalue = Fix((secondvalue - dayvalue * 24 * 3600 - hourvalue * 3600) / 60)
    If minitevalue < 0 Then hourvalue = hourvalue - 1: minitevalue = 60 + minitevalue
    secvalue = secondvalue - dayvalue * 24 * 3600 - hourvalue * 3600 - minitevalue * 60
    If secvalue < 0 Then minitevalue = minitevalue - 1: secvalue = 60 + secvalue
    GetDoTime=dayvalue & "天" & hourvalue & "小时" & minitevalue & "分" & secvalue & "秒"

 End function

原文转自:http://www.ltesting.net