我需要将秒转换为小时:分钟:第二。
例如:685转换为00:11:25
我该如何实现?
我找不到Brightscript文档中的方法
http://sdkdocs.roku.com/display/sdkdoc/ifdateTime#ifdateTime-fromsecondsnumsecondsastegerasvoid
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
这解决了问题
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
怎么样
'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")
使用rodatetime组件,使用seconds()的方法获取时间戳。然后从这个时间戳您可以获得getminutes()gethours()和geteconds()