Player Duration to hh:mm:ss
Garrett Hylltun
garretthylltun at gmail.com
Mon Dec 19 18:00:57 EST 2005
Hi again Bill and list,
Your player time convert works great except it was missing one thing,
so here's a fixed version in case anyone else was going to use the
same bit of code (there's a note between ---> and <--- that describes
the changed code):
function ConvertSeconds mySecondsTime
if isNumber(mySecondsTime) then
-- 3600 seconds in an hour
put the trunc of (mySecondsTime / 3600) into myHours
if myHours < 10 then put "0" before myHours -- leading zero
-- 60 seconds in a minute
put the trunc of ((mySecondsTime - (3600 * myHours)) / 60) into
myMinutes
if myMinutes < 10 then put "0" before MyMinutes -- leading zero
-- the remainder is seconds
put the trunc of (mySecondsTime - 3600 * myHours - 60 *
myMinutes) into mySeconds
-- ---> the above needed a "trunc" issued like further above
<-------
if mySeconds < 10 then put "0" before MySeconds -- leading zero
return myHours & ":" & myMinutes & ":" & mySeconds
else
return "Error: ConvertSeconds() requires a number"
end if
end ConvertSeconds
-Garrett
On Dec 19, 2005, at 11:40 AM, Bill Marriott wrote:
> ===================================
>
> function ConvertSeconds mySecondsTime
>
> if isNumber(mySecondsTime) then
>
> -- 3600 seconds in an hour
> put the trunc of (mySecondsTime / 3600) into myHours
> if myHours < 10 then put "0" before myHours -- leading zero
>
> -- 60 seconds in a minute
> put the trunc of ((mySecondsTime - (3600 * myHours)) / 60) into
> myMinutes
> if myMinutes < 10 then put "0" before MyMinutes -- leading zero
>
> -- the remainder is seconds
> put mySecondsTime - 3600 * myHours - 60 * myMinutes into mySeconds
> if mySeconds < 10 then put "0" before MySeconds -- leading zero
> return myHours & ":" & myMinutes & ":" & mySeconds
>
> else
>
> return "Error: ConvertSeconds() requires a number"
>
> end if
>
> end ConvertSeconds
>
> ===================================
More information about the use-livecode
mailing list