0

I need to convert seconds to Hour:Minute:Second.

For example: 685 converted to 00:11:25

How can I achieve this?

I can't find a method from brightscript documentation

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

Shijin TR
  • 7,516
  • 10
  • 55
  • 122
  • I tried all below answer functions. For add offset and fetch hours and minutes like `diffInSeconds = m.date2.AsSeconds() + m.date1.GetTimeZoneOffset()` But, Here, I found wrong value`0445020:054:030`. Is there any way to add offset and fetch hours and minutes? – Nikunj Chaklasiya Aug 04 '20 at 14:54

4 Answers4

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
TheEndless
  • 301
  • 1
  • 3
0

This solve the issue

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
Shijin TR
  • 7,516
  • 10
  • 55
  • 122
0

How about

'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")
Nas Banov
  • 28,347
  • 6
  • 48
  • 67
0

With roDateTime component, use method FromSeconds() to get the TimeStamp. and then from this TimeStamp you can get GetMinutes() GetHours() and GetSeconds()

Abhishek
  • 3,304
  • 4
  • 30
  • 44