AS3 Convert SECONDS TO HOURS, MINUTES, SECONDS
Posted by robert | Filed under ActionScript 3
Here is a little Flash code snippet to convert the seconds from your audio or video time display project into hours, minutes and remaining seconds (HH:MM:SS). The code is for ActionScript 3.0 but to make it combatable with ActionScript 2.0. Just change the uint data type to Number and it will work fine.
function convertToHHMMSS($seconds:Number):String
{
var s:Number = $seconds % 60;
var m:Number = Math.floor(($seconds % 3600 ) / 60);
var h:Number = Math.floor($seconds / (60 * 60));
var hourStr:String = (h == 0) ? "" : doubleDigitFormat(h) + ":";
var minuteStr:String = doubleDigitFormat(m) + ":";
var secondsStr:String = doubleDigitFormat(s);
return hourStr + minuteStr + secondsStr;
}
function doubleDigitFormat($num:uint):String
{
if ($num < 10)
{
return ("0" + $num);
}
return String($num);
}
trace( convertToHHMMSS(10701) );
//Output = 02:58:21
January 6, 2012 at 3:38 am
Thanks for sharing that little snipet, was very handy!
February 13, 2012 at 10:56 am
Thanks you sir!.
This worked out of the box and spared me the thinking and development.
Nice work.
Much appreciated.
-Ed