我需要将秒数转换为小时:分钟:秒。
例如:685转换为00:11:25
我怎样才能做到这一点?
我无法从brightscript文档中找到方法
http://sdkdocs.roku.com/display/sdkdoc/ifDateTime#ifDateTime-FromSecondsnumSecondsasIntegerasVoid
答案 0 :(得分: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
答案 1 :(得分: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")
答案 2 :(得分:0)
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
答案 3 :(得分:0)
使用roDateTime组件,使用方法FromSeconds()来获取TimeStamp。然后从这个TimeStamp你可以得到GetMinutes()GetHours()和GetSeconds()