0

我们可以使用 VBScript 以 Day-Hour-Minutes 格式获取两个日期值的差异吗?

4

1 回答 1

8

这是一个 HH::MM:SS 示例,将其更改为 DD::HH::MM 应该很容易

ASP FAQ - 日期时间例程操作

<% 
    Function TimeSpan(dt1, dt2) 
        If (isDate(dt1) And IsDate(dt2)) = false Then 
            TimeSpan = "00:00:00" 
            Exit Function 
        End If 

        seconds = Abs(DateDiff("S", dt1, dt2)) 
        minutes = seconds \ 60 
        hours = minutes \ 60 
        minutes = minutes mod 60 
        seconds = seconds mod 60 

        if len(hours) = 1 then hours = "0" & hours 

        TimeSpan = hours & ":" & _ 
            RIGHT("00" & minutes, 2) & ":" & _ 
            RIGHT("00" & seconds, 2) 
    End Function 

    d1 = "2002-03-27 9:20:25 AM" 
    d2 = "2002-03-27 9:20:45 AM" 

    Response.Write TimeSpan(d1, d2) 
%>

类似的东西:(我不确定,我不知道 vbscript)

<% 
    Function TimeSpan(dt1, dt2) 
        If (isDate(dt1) And IsDate(dt2)) = false Then 
            TimeSpan = "00:00:00" 
            Exit Function 
        End If 

        seconds = Abs(DateDiff("S", dt1, dt2)) 
        minutes = seconds \ 60 
        hours = minutes \ 60 
        days  = hours \ 24
        minutes = minutes mod 60 
        seconds = seconds mod 60 
        hours   = hours   mod 24 

        if len(hours) = 1 then hours = "0" & hours 

        TimeSpan = days& ":" & _ 
            RIGHT("00" & hours , 2) & ":" & _ 
            RIGHT("00" & minutes, 2) 
    End Function 

    d1 = "2002-03-27 9:20:25 AM" 
    d2 = "2002-03-27 9:20:45 AM" 

    Response.Write TimeSpan(d1, d2) 
%>
于 2012-12-11T13:35:14.083 回答