AS3: TimeCode Converter


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



Copy this code and paste it in your HTML
  1. public static function timeCode(sec:Number):String
  2. {
  3. var h:Number = Math.floor(sec/3600);
  4. h = isNaN(h) ? 0 : h;
  5.  
  6. var m:Number = Math.floor((sec%3600)/60);
  7. m = isNaN(m) ? 0 : m;
  8.  
  9. var s:Number = Math.floor((sec%3600)%60);
  10. s = isNaN(s) ? 0 : s;
  11.  
  12. return (h == 0 ? "":(h<10 ? "0"+h.toString()+":" : h.toString()+":"))+(m<10 ? "0"+m.toString() : m.toString())+":"+(s<10 ? "0"+s.toString() : s.toString());
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.