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
March 24, 2012 at 9:39 am
Thanks for this. Much quicker and simpler than what I was trying to get working.
June 13, 2012 at 11:00 pm
thanks, it’s work nicely
July 12, 2012 at 4:05 pm
Thanks very much!
August 16, 2012 at 10:03 am
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?
September 11, 2012 at 6:35 am
Thanks.
April 2, 2013 at 11:29 pm
Thanks, you save time.
June 11, 2013 at 10:32 am
Thank you! Very very handy!
January 12, 2014 at 12:21 am
Thanks a lot!
January 22, 2014 at 12:31 am
Hai thanks its really use full to me in that i just add one more thing for date
June 19, 2014 at 12:32 pm
Thanks very much.
October 28, 2014 at 1:40 am
thanks it’s work
August 31, 2015 at 8:04 am
Thanks.. this saved me some time.
February 13, 2018 at 7:58 am
Thank you so much for this piece of code. works like a charm.
February 13, 2018 at 10:52 pm
Thank you sharing this. saved me a lot of time.