0

我需要将秒转换为 Hour:Minute:Second。

例如:685 转换为 00:11:25

我怎样才能做到这一点?

我在 Brightscript 文档中找不到方法

http://sdkdocs.roku.com/display/sdkdoc/ifDateTime#ifDateTime-FromSecondsnumSecondsasIntegerasVoid

4

4 回答 4

2
Function GetDurationString(totalSeconds = 0 As Integer) As String
    remaining = totalSeconds
    hours = Int(remaining / 3600).ToStr()
    remaining = remaining Mod 3600
    minutes = Int(remaining / 60).ToStr()
    remaining = remaining Mod 60
    seconds = remaining.ToStr()

    If hours <> "0" Then
        Return PadLeft(hours, "0", 2) + ":" + PadLeft(minutes, "0", 2) + ":" + PadLeft(seconds, "0", 2)
    Else
        Return PadLeft(minutes, "0", 2) + ":" + PadLeft(seconds, "0", 2)
    End If
End Function

Function PadLeft(value As String, padChar As String, totalLength As Integer) As String
    While value.Len() < totalLength
        value = padChar + value
    End While
    Return value
End Function
于 2015-05-21T22:17:32.133 回答
0

这解决了问题

Function gmdate(seconds as Dynamic) as Dynamic 
  a   = seconds
  b   = 60
  c   = Fix(a / b)
  sec = a - b * c


 a   = Fix(a/60)
 b   = 60
 c   = Fix(a / b)
 min = a - b * c

 a   = Fix(a/60)
 b   = 60
 c   = Fix(a / b)
 hour = a - b * c

if sec > 9
 sec = sec.toStr()
else
  sec = "0"+sec.toStr()
end if 

 if min > 9
  min = min.toStr()
 else
  min = "0"+min.toStr()
 end if 

if hour > 9
 hour = hour.toStr()
else
 hour = "0"+hour.toStr()
end if 
 tmes_string =  hour+":"+min+":"+sec
 return tmes_string
End FUnction
于 2015-05-19T09:48:58.720 回答
0

怎么样

'e.g. tm = 685
hrs = int(tm / 3600)
mins = int(tm / 60) % 60
secs = tm % 60
time_str = str(hrs).replace(" ", "0") + ":" + str(mins).replace(" ", "0") + ":" + str(secs).replace(" ", "0")
于 2015-05-19T22:21:24.023 回答
0

使用 roDateTime 组件,使用 FromSeconds() 方法获取时间戳。然后从这个 TimeStamp 你可以得到 GetMinutes() GetHours() 和 GetSeconds()

于 2015-06-24T19:02:30.420 回答