VBScript - 我们可以通过代码找出以秒为单位的持续时间吗

VBScript - Can we find out duration with seconds through code

我有时间以秒为单位......如下所示

set seconds = 180 seconds
set seconds1 = 1500 Seconds
set seconds2 = 600 Seconds

基于以上值输出如下

duration = 00:03:00 
duration = 00:25:00
duration = 00:10:00

如我需要通过 VBscript 请帮助我

您可以通过将总秒数除以小时和分钟来手动构建 HH:MM:SS 字符串:

Function FormatSeconds(p_lngSeconds)

    Dim sReturn
    Dim lngTotalSeconds
    Dim iHours
    Dim iMinutes
    
    ' Copy value from parameter
    lngTotalSeconds = p_lngSeconds
    
    ' Calculate number of hours
    iHours = Int(lngTotalSeconds / (60 * 60))
    
    ' Subtract from total seconds
    lngTotalSeconds = lngTotalSeconds - (iHours * 60 * 60)
    
    ' Calculate numer of minutes
    iMinutes = Int(lngTotalSeconds / 60)
    
    ' Subtract from total seconds
    lngTotalSeconds = lngTotalSeconds - (iMinutes * 60)
    
    ' Build string
    sReturn = iHours & ":" & Right("0" & iMinutes, 2) & ":" & Right("0" & lngTotalSeconds, 2)

    FormatSeconds = sReturn

End Function

回到你的问题,你会这样使用这个函数:

duration = FormatSeconds(seconds)