ActionScript Seconds to Standard Time Format

/ Published in: ActionScript 3
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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

You need to login to post a comment.