Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

Formatting Video Lengths

I could not find a way to format the duration of my videos on demand, so I just wrote a simple function. It's probably not the most efficient but it gets the job done. Felt like sharing, maybe I can save someone 5 minutes. Or maybe ten if they spend five on google searches.

Function formatTime(duration) as String
time_string = ""
hours = Int(duration/3600)
minutes = Int(duration/60)
minutes = minutes - (hours*60)
seconds = duration - (minutes * 60) - (hours*3600)
if(hours.tostr() <> "0")
time_string = hours.tostr() + "h "
End If
if(minutes.tostr() <> "0")
time_string = time_string + minutes.tostr() + "m "
End if
if(seconds.tostr() <> "0")
time_string = time_string + seconds.tostr() + "s"
End if
return time_string
End Function
0 Kudos