在 VBScript 中将秒转换为周、天、小时、分钟、秒

发布于 2024-07-18 02:07:23 字数 93 浏览 5 评论 0原文

vbscript中有没有将指定秒数转换为周/日/小时/分钟/秒时间格式的函数?

例如:969234 秒 = 1 周 4 天 5 小时 13 分 54 秒

Is there a function to convert a specified number of seconds into a week/day/hour/minute/second time format in vbscript?

eg: 969234 seconds = 1wk 4days 5hrs 13mins 54secs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝影如岚 2024-07-25 02:07:23
Dim myDate
dim noWeeks
dim noDays
dim tempWeeks
dim pos 
myDate = DateAdd("s",969234,CDate(0))

tempWeeks = FormatNumber(myDate / 7,10)
pos = instr(tempWeeks, ".")
if pos > 1 then
    tempWeeks = left(myDate, pos -1)
end if
noWeeks = Cint(tempWeeks)

noDays = Cint(((myDate / 7) - noWeeks) * 7)

wscript.echo noWeeks & "wk " & noDays & "days " & datepart("h", myDate) & "hrs " & datepart("n", myDate) & "mins " & datepart("s", myDate) & "secs"
Dim myDate
dim noWeeks
dim noDays
dim tempWeeks
dim pos 
myDate = DateAdd("s",969234,CDate(0))

tempWeeks = FormatNumber(myDate / 7,10)
pos = instr(tempWeeks, ".")
if pos > 1 then
    tempWeeks = left(myDate, pos -1)
end if
noWeeks = Cint(tempWeeks)

noDays = Cint(((myDate / 7) - noWeeks) * 7)

wscript.echo noWeeks & "wk " & noDays & "days " & datepart("h", myDate) & "hrs " & datepart("n", myDate) & "mins " & datepart("s", myDate) & "secs"
烟花肆意 2024-07-25 02:07:23

没有内置函数可以做到这一点。

这是一个快速而肮脏的:-

Function SecondsToString(totalSeconds)

    Dim work : work = totalSeconds

    Dim seconds
    Dim minutes
    Dim hours
    Dim days
    Dim weeks

    seconds = work Mod 60
    work = work \ 60
    minutes = work Mod 60
    work = work \ 60
    hours = work Mod 24
    work = work \ 24
    days = work Mod 7
    work = work \ 7
    weeks = work

    Dim s: s = ""
    Dim renderStarted: renderStarted = False

    If (weeks <> 0) Then
        renderStarted = True
        s = s & CStr(weeks)
        If (weeks = 1) Then
            s = s & "wk "
        Else
            s = s & "wks "
        End If
    End If

    If (days <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(days)
        If (days = 1) Then
            s = s & "day "
        Else
            s = s & "days "
        End If
    End If

    If (hours <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(hours)
        If (hours = 1) Then
            s = s & "hr "
        Else
            s = s & "hrs "
        End If
    End If

    If (minutes <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(minutes)
        If (minutes = 1) Then
            s = s & "min "
        Else
            s = s & "mins "
        End If
    End If

    s = s & CStr(seconds)
    If (seconds = 1) Then
        s = s & "sec "
    Else
        s = s & "secs "
    End If

    SecondsToString = s

End Function

No built in function to do that.

Here is a quick and dirty one:-

Function SecondsToString(totalSeconds)

    Dim work : work = totalSeconds

    Dim seconds
    Dim minutes
    Dim hours
    Dim days
    Dim weeks

    seconds = work Mod 60
    work = work \ 60
    minutes = work Mod 60
    work = work \ 60
    hours = work Mod 24
    work = work \ 24
    days = work Mod 7
    work = work \ 7
    weeks = work

    Dim s: s = ""
    Dim renderStarted: renderStarted = False

    If (weeks <> 0) Then
        renderStarted = True
        s = s & CStr(weeks)
        If (weeks = 1) Then
            s = s & "wk "
        Else
            s = s & "wks "
        End If
    End If

    If (days <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(days)
        If (days = 1) Then
            s = s & "day "
        Else
            s = s & "days "
        End If
    End If

    If (hours <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(hours)
        If (hours = 1) Then
            s = s & "hr "
        Else
            s = s & "hrs "
        End If
    End If

    If (minutes <> 0 OR renderStarted) Then
        renderStarted = True
        s = s & CStr(minutes)
        If (minutes = 1) Then
            s = s & "min "
        Else
            s = s & "mins "
        End If
    End If

    s = s & CStr(seconds)
    If (seconds = 1) Then
        s = s & "sec "
    Else
        s = s & "secs "
    End If

    SecondsToString = s

End Function
挽心 2024-07-25 02:07:23

您想使用 timer 伪变量:

start = timer
Rem do something long
duration_in_seconds = timer - start
wscript.echo "Duration " & duration_in_seconds & " seconds."

You wantto use timer pseudo-variable :

start = timer
Rem do something long
duration_in_seconds = timer - start
wscript.echo "Duration " & duration_in_seconds & " seconds."
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文