Previous Page
Next Page

Recipe 14.5. Formatting Seconds or Milliseconds as Minutes and Seconds

Problem

You want to display seconds or milliseconds in minutes and seconds (mm:ss) format.

Solution

Use either the custom ascb.util.DateFormat.formatSeconds( ) or ascb.util.DateFormat.formatMilliseconds( ) methods.

Discussion

Many values in ActionScript are given in milliseconds or seconds. For example, sound lengths are given in milliseconds. However, in most cases, you want to format the value as minutes and seconds when displaying it to the user. You can accomplish this with a short amount of code. To further simplify things, that code has already been made into static methods of the DateFormat class.

The ascb.utils.DateFormat class has two methods that convert a number to the format mm:ss. The formatSeconds( ) method converts seconds to that format, while the formatMilliseconds( ) method converts milliseconds to that format.

See Also

Recipe 14.4


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)