Posted By

withinmedianl on 11/20/10


Tagged

time convert


Versions (?)

Convert number (time) to more readable time


 / Published in: ActionScript 3
 

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

  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  

You need to login to post a comment.