ProblemYou want to retrieve the name of the day or month. SolutionCreate arrays that contain the string values for the names of the days of the week and the names of the months of the year. Use the numeric day and month to extract the string values from the arrays. DiscussionThe ActionScript Date class provides the day and month properties, which return integer values representing the day of the week (from 0 to 6) and the month of the year (from 0 to 11). However, you may want the name of the day or month instead of its zero-relative number. To address this, create arrays containing the names of the days and months. Or, more conveniently, you can use constants of the custom ascb. util.DateFormat class. The constants DAYS, DAYS_ABBREVIATED, MONTHS, and MONTHS_ABBREVIATED are each arrays that contain strings that correspond to the numeric values returned by day and month. The actual definitions of those constants are as follows: public static const DAYS:Array = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; public static const DAYSABBREVIATED:Array = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]; public static const MONTHS:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; public static const MONTHSABBREVIATED:Array = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; You can then use those constants as shown in the following example: var example:Date = new Date(2010, 3, 10); trace(DateFormat.DAYS[example.day]); // Displays: Saturday trace(DateFormat.DAYSABBREVIATED[example.day]); // Displays: Sat trace(DateFormat.MONTHS[example.month]); // Displays: April trace(DateFormat.MONTHSABBREVIATED[example.month]); // Displays: Apr See AlsoRecipe 14.4 |