Timecode Utility
Today I’m sharing simple utility that I use from time to time when I need to convert time (see what I did there?
)
It’s very useful if you build a FLV player for example, and want to convert the time into minutes:seconds
Example of how to apply it to your project:
import com.vamapaull.utils.TimeUtil; time.text = TimeUtil.getTimecode(timeValue);
Results:

The ActionScript class:
package com.vamapaull.utils { public class TimeUtil { public static function getTimecode(value:Number):String { var t:Number = Math.round(value), min:Number = Math.floor(t/60), sec:Number = t%60, tc:String = ""; if(min < 10) tc += "0"; if(min >= 1) { if (isNaN(min) == true) tc += "0"; else tc += min.toString(); } else tc += "0"; tc += ":"; if(sec < 10) { tc += "0"; if (isNaN(sec) == true) tc += "0"; else tc += sec.toString(); } else { if (isNaN(sec) == true) tc += "0"; else tc += sec.toString(); } return tc; } } }
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

























