| Package | system.formatters |
| Class | public class DateFormatter |
| Inheritance | DateFormatter Object |
| Implements | Formattable |
Use the declared constants as placeholders for specific parts of the date-time.
All characters from 'A' to 'Z' and from 'a' to 'z' are reserved, although not all of these characters are interpreted right now.
If you want to include plain text in the pattern put it into quotes (') to avoid interpretation.
If you want a quote in the formatted date-time, put two quotes directly after one another.
For example: "hh 'o''clock'"
Example :
import system.formatter.DateFormatter ;
var f:DateFormatter = new DateFormatter() ;
f.pattern = "yyyy DDDD d MMMM - hh 'h' nn 'mn' ss 's'" ;
var result:String = f.format() ;
trace("pattern : " + f.pattern) ;
trace("result : " + result) ;
trace("----") ;
f.pattern = "DDDD d MMMM yyyy" ;
var result:String = f.format(new Date(2005, 10, 22)) ;
trace("pattern : " + f.pattern) ;
trace("result : " + result) ;
trace("----") ;
f.pattern = "hh 'h' nn 'mn' ss 's' tt" ;
trace( f.format( new Date(2008,1,21,10,15,0,0) ) ) ; // 10 h 15 mn 00 s am
f.pattern = "hh 'h' nn 'mn' ss 's' t" ;
trace( formatter.format( new Date(2008,1,21,10,15,0,0) ) ) ; // 10 h 15 mn 00 s a
f.pattern = "hh 'h' nn 'mn' ss 's' TT" ; // capitalize the pm expression.
trace( formatter.format( new Date(2008,1,21,14,15,0,0) ) ) ; // 02 h 15 mn 00 s PM
| Property | Defined By | ||
|---|---|---|---|
| DEFAULT_AM_EXPRESSION : String = am [static]
The default AM/PM designator expression. | DateFormatter | ||
| DEFAULT_PM_EXPRESSION : String = pm [static]
The default AM/PM designator expression. | DateFormatter | ||
| _pattern : String
The internal pattern of this formatter. | DateFormatter | ||
| pattern : String
Indicates the internal pattern of this formatter. | DateFormatter | ||
| Method | Defined By | ||
|---|---|---|---|
DateFormatter(pattern:String = dd.mm.yyyy HH:nn:ss)
Creates a new DateFormatter instance. | DateFormatter | ||
clone():*
Creates and returns a shallow copy of the object. | DateFormatter | ||
format(value:* = null):String
Formats the specified value. | DateFormatter | ||
formatDayAsNumber(day:Number, cpt:Number):String
Formats the specified number day value in a string representation. | DateFormatter | ||
formatDayAsText(day:Number, cpt:Number):String
Formats the specified day value in a string representation. | DateFormatter | ||
formatDesignator(hour:Number, cpt:Number, capitalize:Boolean):String
Formats the designator AM/PM in string expression. | DateFormatter | ||
formatHourInAmPm(hour:Number, cpt:Number):String
Formats the specified hour value in a string representation with the am-pm notation. | DateFormatter | ||
formatHourInDay(hour:Number, cpt:Number):String
Formats an hour number in string expression. | DateFormatter | ||
formatMillisecond(millisecond:Number, cpt:Number):String
Formats a millisecond value number in string expression. | DateFormatter | ||
formatMinute(minute:Number, cpt:Number):String
Formats a minute value number in string expression. | DateFormatter | ||
formatMonthAsNumber(month:Number, cpt:Number):String
Formats a month value number in string expression. | DateFormatter | ||
formatMonthAsText(month:Number, cpt:Number):String
Formats a month text value in string expression. | DateFormatter | ||
formatSecond(second:Number, cpt:Number):String
Format the second value passed in argument. | DateFormatter | ||
formatYear(year:Number, cpt:Number):String
Format the year value passed in argument. | DateFormatter | ||
getMonthNames():Array
Retrieves a list of localized strings containing the month names for the current calendar system. | DateFormatter | ||
getWeekdayNames():Array
Retrieves a list of localized strings containing the names of weekdays for the current calendar system. | DateFormatter | ||
getZeros(cpt:Number):String
Returns a string representation fill by 0 values or an empty string if the cpt value is NaN or <1. | DateFormatter | ||
setMonthNames(names:Array):void
Sets a list of localized strings containing the month names for the current calendar system. | DateFormatter | ||
setWeekdayNames(names:Array):void
Sets a list of localized strings containing the month names for the current calendar system. | DateFormatter | ||
| Constant | Defined By | ||
|---|---|---|---|
| AM_PM : String = t [static]
Placeholder for AM/PM designator who indicates if the hour is is before or after noon in date format. | DateFormatter | ||
| CAPITAL_AM_PM : String = T [static]
Placeholder for AM/PM designator who indicates if the hour is is before or after noon in date format. | DateFormatter | ||
| DAY_AS_NUMBER : String = d [static]
Placeholder for day in month as number in date format. | DateFormatter | ||
| DAY_AS_TEXT : String = D [static]
Placeholder for day in week as text in date format. | DateFormatter | ||
| DEFAULT_DATE_FORMAT : String = dd.mm.yyyy HH:nn:ss [static]
The default date format pattern "dd.mm.yyyy HH:nn:ss". | DateFormatter | ||
| HOUR_IN_AM_PM : String = h [static]
Placeholder for hour in am/pm (1 - 12) in date format. | DateFormatter | ||
| HOUR_IN_DAY : String = H [static]
Placeholder for hour in day (0 - 23) in date format. | DateFormatter | ||
| MILLISECOND : String = S [static]
Placeholder for millisecond in date format. | DateFormatter | ||
| MINUTE : String = n [static]
Placeholder for minute in hour in date format. | DateFormatter | ||
| MONTH_AS_NUMBER : String = m [static]
Placeholder for month in year as number in date format. | DateFormatter | ||
| MONTH_AS_TEXT : String = M [static]
Placeholder for month in year as text in date format. | DateFormatter | ||
| QUOTE : String = ' [static]
Quotation beginning and ending token. | DateFormatter | ||
| RANGE_DAY_AS_TEXT : Range [static]
The internal range use to defined the days as text in the DateFormatter. | DateFormatter | ||
| RANGE_HOUR : Range [static]
The internal range use to defined the hours in the DateFormatter. | DateFormatter | ||
| RANGE_MILLISECOND : Range [static]
The internal range use to defined the milliseconds in the DateFormatter. | DateFormatter | ||
| RANGE_MINUTE : Range [static]
The internal range use to defined the minutes in the DateFormatter. | DateFormatter | ||
| RANGE_MONTH : Range [static]
The internal range use to defined the months in the DateFormatter. | DateFormatter | ||
| RANGE_SECOND : Range [static]
The internal range use to defined the seconds in the DateFormatter. | DateFormatter | ||
| SECOND : String = s [static]
Placeholder for second in minute in date format. | DateFormatter | ||
| YEAR : String = y [static]
Placeholder for year in date format. | DateFormatter | ||
| _pattern | property |
public var _pattern:StringThe internal pattern of this formatter.
| DEFAULT_AM_EXPRESSION | property |
public static var DEFAULT_AM_EXPRESSION:String = amThe default AM/PM designator expression.
| DEFAULT_PM_EXPRESSION | property |
public static var DEFAULT_PM_EXPRESSION:String = pmThe default AM/PM designator expression.
| pattern | property |
pattern:StringIndicates the internal pattern of this formatter.
public function get pattern():String public function set pattern(value:String):void| DateFormatter | () | Constructor |
public function DateFormatter(pattern:String = dd.mm.yyyy HH:nn:ss)Creates a new DateFormatter instance.
If you do not pass-in a pattern or if the passed-in one is null or undefined the constant DEFAULT_DATE_FORMAT is used ("dd.mm.yyyy HH:nn:ss").
Parameterspattern:String (default = dd.mm.yyyy HH:nn:ss) — (optional) the pattern describing the date and time format.
|
| clone | () | method |
public function clone():*Creates and returns a shallow copy of the object.
Returns* — A new object that is a shallow copy of this instance.
|
| format | () | method |
public function format(value:* = null):StringFormats the specified value.
import system.formatter.DateFormatter ;
var f:DateFormatter = new DateFormatter() ;
f.pattern = "yyyy DDDD d MMMM - hh 'h' nn 'mn' ss 's'" ;
var result:String = f.format() ;
trace("pattern : " + f.pattern) ;
trace("result : " + result) ;
f.pattern = "DDDD d MMMM yyyy" ;
var result:String = f.format(new Date(2005, 10, 22)) ;
trace("pattern : " + f.pattern) ;
trace("result : " + result) ;
f.pattern = "hh 'h' nn 'mn' ss 's' tt" ;
trace( f.format( new Date(2008,1,21,10,15,0,0) ) ) ; // 02 h 15 mn 00 s am
f.pattern = "hh 'h' nn 'mn' ss 's' t" ;
trace( formatter.format( new Date(2008,1,21,10,15,0,0) ) ) ; // 02 h 15 mn 00 s a
f.pattern = "hh 'h' nn 'mn' ss 's' TT" ; // capitalize the pm expression.
trace( formatter.format( new Date(2008,1,21,14,15,0,0) ) ) ; // 02 h 15 mn 00 s PM
Parameters
value:* (default = null) — The object to format.
|
String — the string representation of the formatted value.
|
| formatDayAsNumber | () | method |
public function formatDayAsNumber(day:Number, cpt:Number):StringFormats the specified number day value in a string representation.
Parameters
day:Number | |
cpt:Number (default = NaN) |
String — the specified numberday value in a string representation.
|
| formatDayAsText | () | method |
public function formatDayAsText(day:Number, cpt:Number):StringFormats the specified day value in a string representation.
Parameters
day:Number | |
cpt:Number (default = NaN) |
String — the specified day value in a string representation.
|
| formatDesignator | () | method |
public function formatDesignator(hour:Number, cpt:Number, capitalize:Boolean):StringFormats the designator AM/PM in string expression.
Parameters
hour:Number | |
cpt:Number | |
capitalize:Boolean |
String — the specified am/pm expression representation.
|
| formatHourInAmPm | () | method |
public function formatHourInAmPm(hour:Number, cpt:Number):StringFormats the specified hour value in a string representation with the am-pm notation.
Parameters
hour:Number | |
cpt:Number (default = NaN) |
String — the specified hour value in a string representation with the am-pm notation.
|
| formatHourInDay | () | method |
public function formatHourInDay(hour:Number, cpt:Number):StringFormats an hour number in string expression.
Parameters
hour:Number | |
cpt:Number (default = NaN) |
String |
| formatMillisecond | () | method |
public function formatMillisecond(millisecond:Number, cpt:Number):StringFormats a millisecond value number in string expression.
Parameters
millisecond:Number | |
cpt:Number (default = NaN) |
String |
| formatMinute | () | method |
public function formatMinute(minute:Number, cpt:Number):StringFormats a minute value number in string expression.
Parameters
minute:Number | |
cpt:Number (default = NaN) |
String |
| formatMonthAsNumber | () | method |
public function formatMonthAsNumber(month:Number, cpt:Number):StringFormats a month value number in string expression.
Parameters
month:Number | |
cpt:Number (default = NaN) |
String |
| formatMonthAsText | () | method |
public function formatMonthAsText(month:Number, cpt:Number):StringFormats a month text value in string expression.
Parameters
month:Number | |
cpt:Number (default = NaN) |
String |
| formatSecond | () | method |
public function formatSecond(second:Number, cpt:Number):StringFormat the second value passed in argument.
Parameters
second:Number | |
cpt:Number (default = NaN) |
String — the second string representation of this DateFormatter.
|
| formatYear | () | method |
public function formatYear(year:Number, cpt:Number):StringFormat the year value passed in argument.
Parameters
year:Number (default = NaN) | |
cpt:Number (default = NaN) |
String — the year string representation of this DateFormatter.
|
| getMonthNames | () | method |
public function getMonthNames():ArrayRetrieves a list of localized strings containing the month names for the current calendar system.
ReturnsArray |
| getWeekdayNames | () | method |
public function getWeekdayNames():ArrayRetrieves a list of localized strings containing the names of weekdays for the current calendar system.
ReturnsArray |
| getZeros | () | method |
public function getZeros(cpt:Number):StringReturns a string representation fill by 0 values or an empty string if the cpt value is NaN or <1.
Parameters
cpt:Number |
String — a string representation fill by 0 values or an empty string if the cpt value is NaN or <1.
|
| setMonthNames | () | method |
public function setMonthNames(names:Array):voidSets a list of localized strings containing the month names for the current calendar system. If you passed-in a null value in the argument of the method, the week days use the default english names.
Example :
import system.formatters.DateFormatter ;
var formatter:DateFormatter = new DateFormatter() ;
// localize with FR month names
formatter.setMonthNames( ["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"] ) ;
Parameters
names:Array |
| setWeekdayNames | () | method |
public function setWeekdayNames(names:Array):voidSets a list of localized strings containing the month names for the current calendar system. If you passed-in a null value in the argument of the method, the week days use the default english names.
Example :
import system.formatters.DateFormatter ;
var formatter:DateFormatter = new DateFormatter() ;
// localize with FR month names
formatter.setWeekdayNames( ["Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"]) ;
Parameters
names:Array |
| AM_PM | Constant |
public static const AM_PM:String = tPlaceholder for AM/PM designator who indicates if the hour is is before or after noon in date format. The output is lower-case. Examples: t -> a or p / tt -> am or pm.
| CAPITAL_AM_PM | Constant |
public static const CAPITAL_AM_PM:String = TPlaceholder for AM/PM designator who indicates if the hour is is before or after noon in date format. The output is capitalized. Examples: T -> T or P / TT -> AM or PM.
| DAY_AS_NUMBER | Constant |
public static const DAY_AS_NUMBER:String = dPlaceholder for day in month as number in date format.
| DAY_AS_TEXT | Constant |
public static const DAY_AS_TEXT:String = DPlaceholder for day in week as text in date format.
| DEFAULT_DATE_FORMAT | Constant |
public static const DEFAULT_DATE_FORMAT:String = dd.mm.yyyy HH:nn:ss
The default date format pattern "dd.mm.yyyy HH:nn:ss".
| HOUR_IN_AM_PM | Constant |
public static const HOUR_IN_AM_PM:String = hPlaceholder for hour in am/pm (1 - 12) in date format.
| HOUR_IN_DAY | Constant |
public static const HOUR_IN_DAY:String = HPlaceholder for hour in day (0 - 23) in date format.
| MILLISECOND | Constant |
public static const MILLISECOND:String = SPlaceholder for millisecond in date format.
| MINUTE | Constant |
public static const MINUTE:String = nPlaceholder for minute in hour in date format.
| MONTH_AS_NUMBER | Constant |
public static const MONTH_AS_NUMBER:String = mPlaceholder for month in year as number in date format.
| MONTH_AS_TEXT | Constant |
public static const MONTH_AS_TEXT:String = MPlaceholder for month in year as text in date format.
| QUOTE | Constant |
public static const QUOTE:String = 'Quotation beginning and ending token.
| RANGE_DAY_AS_TEXT | Constant |
public static const RANGE_DAY_AS_TEXT:RangeThe internal range use to defined the days as text in the DateFormatter.
| RANGE_HOUR | Constant |
public static const RANGE_HOUR:RangeThe internal range use to defined the hours in the DateFormatter.
| RANGE_MILLISECOND | Constant |
public static const RANGE_MILLISECOND:RangeThe internal range use to defined the milliseconds in the DateFormatter.
| RANGE_MINUTE | Constant |
public static const RANGE_MINUTE:RangeThe internal range use to defined the minutes in the DateFormatter.
| RANGE_MONTH | Constant |
public static const RANGE_MONTH:RangeThe internal range use to defined the months in the DateFormatter.
| RANGE_SECOND | Constant |
public static const RANGE_SECOND:RangeThe internal range use to defined the seconds in the DateFormatter.
| SECOND | Constant |
public static const SECOND:String = sPlaceholder for second in minute in date format.
| YEAR | Constant |
public static const YEAR:String = yPlaceholder for year in date format.