The DateTimeFormatter class formats Date values into date
and time strings according to the conventions of a specific locale.
Formatting follows a pattern string which contains sequences
of letters that are replaced with date or time values. For example,
in the pattern "yyyy/MM" the characters "yyyy" are replaced with
a four-digit year, followed by a "/" character, and a two-digit
The pattern string can be set explicitly using the setDateTimePattern()
method. However it is best to let the pattern be set automatically
according to the user’s locale and operating system preferences.
This practice helps assure that the result is culturally appropriate.
The DateTimeFormatter can represent dates and times in three
standard styles (LONG, MEDIUM, and SHORT) and it can also use a
CUSTOM pattern. One style can be used for the date, and a second
style for the time. The actual patterns used for each style vary
somewhat by operating system.
You can specify the styles when you create a DateTimeFormatter
object. If the style parameters are not specified, then they are
set to DateTimeStyle.LONG by default. You can change the styles
later by using the setDateTimeStyles() method, as shown in the following
var date:Date = new Date(2009, 2, 27, 13, 1);
var dtf:DateTimeFormatter = new DateTimeFormatter("en-US",
var longDate:String = dtf.format(date);
trace(longDate); // March 27, 2009 1:01:00 PM
var shortDate:String = dtf.format(date);
trace(shortDate); // 3/27/09 1:01 PM