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

16 Responses to “AS3 Convert SECONDS TO HOURS, MINUTES, SECONDS”

  1. Thanks for sharing that little snipet, was very handy!

  2. Thanks you sir!.
    This worked out of the box and spared me the thinking and development.
    Nice work.
    Much appreciated.

  3. Thanks for this. Much quicker and simpler than what I was trying to get working.

  4. thanks, it’s work nicely

  5. Thanks very much!

  6. Thanks, this is awesome. I have a need to do the opposite: I have a variable that is always in the HH:MM:SS.s format, and I want to convert it to all minutes, lets say, add it to a new variable that will be part of a division function. Can you help?

  7. Thanks.

  8. Abdur Rahman Says:
    April 2, 2013 at 11:29 pm

    Thanks, you save time.

  9. Thank you! Very very handy!

  10. Thanks a lot!

  11. Hai thanks its really use full to me in that i just add one more thing for date

  12. Thanks very much.

  13. thanks it’s work

  14. Thanks.. this saved me some time.

  15. Sumeet Basak Says:
    February 13, 2018 at 7:58 am

    Thank you so much for this piece of code. works like a charm.

  16. Thank you sharing this. saved me a lot of time.

Leave a Reply