Platforms to show: All Mac Windows Linux Cross-Platform
FAQ - Graphics.Can anyone help me convert seconds to time in this format hh:mm:ss?
Answer:
Sure, here's a routine I use (which has an advantage over the previously-posted Date-based solution in that you don't have to rely on the creation of an object -- all that happens is some division and string concatenation):
Example
Function SecsToTimeString(timeInSecs as Integer , padHours as boolean , padMinutes as boolean ) as string // Given an amount time (in seconds), generates a string representing that amount // of time. The padHours and padMinutes parameters determine whether to display // hours and minutes if their values are zero. // Examples: // timeInSecs = 90, padHours = true; returns "00:01:30" // timeInSecs = 1, padHours = false, padMinutes = true; returns "00:01" // timeInSecs = 3601, padMinutes = false; returns "01:00:01" dim hours, minutes, seconds as Integer dim hoursString, minutesString as string hours = timeInSecs / 3600 minutes = (timeInSecs mod 3600 ) / 60 seconds = timeInSecs mod 60 if hours = 0 then if padHours then hoursString = "00:" else hoursString = "" end if else hoursString = Format(hours, "##\:" ) end if if minutes = 0 then if hours <> 0 or padMinutes then minutesString = "00:" else minutesString = "" end if else minutesString = Format(minutes, "00\:" ) end if return hoursString + minutesString + Format(seconds, "00" )End Function
(from the rb mailinglist)