Convert number (time) to more readable time


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

based on: http://www.snipplr.com/view/33913/actionscript-seconds-to-standard-time-format/


Copy this code and paste it in your HTML
  1. private function convertTime(secs:Number, format:String = ""):String
  2. {
  3. var toReturn:String;
  4.  
  5. var h:Number=Math.floor(secs/3600);
  6. var m:Number=Math.floor((secs%3600)/60);
  7. var s:Number=Math.floor((secs%3600)%60);
  8. if (format)
  9. {
  10. if(format == "h")
  11. {
  12. toReturn = (h==0?"":(h<10?"0"+h.toString()+":":h.toString()));
  13. }
  14. else if(format == "m")
  15. {
  16. toReturn = ((m<10?"0"+m.toString():m.toString()));
  17. }
  18. else if(format == "s")
  19. {
  20. toReturn = ((s<10?"0"+s.toString():s.toString()));
  21. }
  22. }
  23. else
  24. {
  25. toReturn = (h==0?"":(h<10?"0"+h.toString()+":":h.toString()+":"))+(m<10?"0"+m.toString():m.toString())+":"+(s<10?"0"+s.toString():s.toString());
  26. }
  27. return toReturn;
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.