Posted By

cessnajumpin on 05/05/10


time actionscript action script standard second seconds

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


ActionScript Seconds to Standard Time Format

 / Published in: ActionScript 3

A quick and easy function to convert seconds into easily readable time. (90 seconds = 01:30)

  1. private function convertTime(secs:Number):String
  2. {
  3. var h:Number=Math.floor(secs/3600);
  4. var m:Number=Math.floor((secs%3600)/60);
  5. var s:Number=Math.floor((secs%3600)%60);
  6. return(h==0?"":(h<10?"0"+h.toString()+":":h.toString()+":"))+(m<10?"0"+m.toString():m.toString())+":"+(s<10?"0"+s.toString():s.toString());
  7. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: withinmedianl on November 20, 2010

Like this it gives you more control:

private function convertTime(secs:Number, format:String = ""):String { var toReturn:String;

        var h:Number=Math.floor(secs/3600);
        var m:Number=Math.floor((secs%3600)/60);
        var s:Number=Math.floor((secs%3600)%60);
        if (format)
            if(format == "h")
                toReturn = (h==0?"":(h
Posted By: withinmedianl on November 20, 2010

Woops, that didn't work. i posted it here: copy and update your version, then notify me and i will delete mine

You need to login to post a comment.