Packagesystem.formatters
Classpublic class DateFormatter
InheritanceDateFormatter Inheritance Object
Implements Formattable

DateFormatter formats a given date with a specified pattern.

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
     



Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
  
Retrieves a list of localized strings containing the month names for the current calendar system.
DateFormatter
  
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
Public Constants
 ConstantDefined 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
Property Detail
_patternproperty
public var _pattern:String

The internal pattern of this formatter.

DEFAULT_AM_EXPRESSIONproperty 
public static var DEFAULT_AM_EXPRESSION:String = am

The default AM/PM designator expression.

DEFAULT_PM_EXPRESSIONproperty 
public static var DEFAULT_PM_EXPRESSION:String = pm

The default AM/PM designator expression.

patternproperty 
pattern:String

Indicates the internal pattern of this formatter.


Implementation
    public function get pattern():String
    public function set pattern(value:String):void
Constructor Detail
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").

Parameters
pattern:String (default = dd.mm.yyyy HH:nn:ss) — (optional) the pattern describing the date and time format.
Method Detail
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):String

Formats 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.

Returns
String — the string representation of the formatted value.
formatDayAsNumber()method 
public function formatDayAsNumber(day:Number, cpt:Number):String

Formats the specified number day value in a string representation.

Parameters

day:Number
 
cpt:Number (default = NaN)

Returns
String — the specified numberday value in a string representation.
formatDayAsText()method 
public function formatDayAsText(day:Number, cpt:Number):String

Formats the specified day value in a string representation.

Parameters

day:Number
 
cpt:Number (default = NaN)

Returns
String — the specified day value in a string representation.
formatDesignator()method 
public function formatDesignator(hour:Number, cpt:Number, capitalize:Boolean):String

Formats the designator AM/PM in string expression.

Parameters

hour:Number
 
cpt:Number
 
capitalize:Boolean

Returns
String — the specified am/pm expression representation.
formatHourInAmPm()method 
public function formatHourInAmPm(hour:Number, cpt:Number):String

Formats the specified hour value in a string representation with the am-pm notation.

Parameters

hour:Number
 
cpt:Number (default = NaN)

Returns
String — the specified hour value in a string representation with the am-pm notation.
formatHourInDay()method 
public function formatHourInDay(hour:Number, cpt:Number):String

Formats an hour number in string expression.

Parameters

hour:Number
 
cpt:Number (default = NaN)

Returns
String
formatMillisecond()method 
public function formatMillisecond(millisecond:Number, cpt:Number):String

Formats a millisecond value number in string expression.

Parameters

millisecond:Number
 
cpt:Number (default = NaN)

Returns
String
formatMinute()method 
public function formatMinute(minute:Number, cpt:Number):String

Formats a minute value number in string expression.

Parameters

minute:Number
 
cpt:Number (default = NaN)

Returns
String
formatMonthAsNumber()method 
public function formatMonthAsNumber(month:Number, cpt:Number):String

Formats a month value number in string expression.

Parameters

month:Number
 
cpt:Number (default = NaN)

Returns
String
formatMonthAsText()method 
public function formatMonthAsText(month:Number, cpt:Number):String

Formats a month text value in string expression.

Parameters

month:Number
 
cpt:Number (default = NaN)

Returns
String
formatSecond()method 
public function formatSecond(second:Number, cpt:Number):String

Format the second value passed in argument.

Parameters

second:Number
 
cpt:Number (default = NaN)

Returns
String — the second string representation of this DateFormatter.
formatYear()method 
public function formatYear(year:Number, cpt:Number):String

Format the year value passed in argument.

Parameters

year:Number (default = NaN)
 
cpt:Number (default = NaN)

Returns
String — the year string representation of this DateFormatter.
getMonthNames()method 
public function getMonthNames():Array

Retrieves a list of localized strings containing the month names for the current calendar system.

Returns
Array
getWeekdayNames()method 
public function getWeekdayNames():Array

Retrieves a list of localized strings containing the names of weekdays for the current calendar system.

Returns
Array
getZeros()method 
public function getZeros(cpt:Number):String

Returns a string representation fill by 0 values or an empty string if the cpt value is NaN or <1.

Parameters

cpt:Number

Returns
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):void

Sets 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):void

Sets 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

Constant Detail
AM_PMConstant
public static const AM_PM:String = t

Placeholder 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_PMConstant 
public static const CAPITAL_AM_PM:String = T

Placeholder 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_NUMBERConstant 
public static const DAY_AS_NUMBER:String = d

Placeholder for day in month as number in date format.

DAY_AS_TEXTConstant 
public static const DAY_AS_TEXT:String = D

Placeholder for day in week as text in date format.

DEFAULT_DATE_FORMATConstant 
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_PMConstant 
public static const HOUR_IN_AM_PM:String = h

Placeholder for hour in am/pm (1 - 12) in date format.

HOUR_IN_DAYConstant 
public static const HOUR_IN_DAY:String = H

Placeholder for hour in day (0 - 23) in date format.

MILLISECONDConstant 
public static const MILLISECOND:String = S

Placeholder for millisecond in date format.

MINUTEConstant 
public static const MINUTE:String = n

Placeholder for minute in hour in date format.

MONTH_AS_NUMBERConstant 
public static const MONTH_AS_NUMBER:String = m

Placeholder for month in year as number in date format.

MONTH_AS_TEXTConstant 
public static const MONTH_AS_TEXT:String = M

Placeholder for month in year as text in date format.

QUOTEConstant 
public static const QUOTE:String = '

Quotation beginning and ending token.

RANGE_DAY_AS_TEXTConstant 
public static const RANGE_DAY_AS_TEXT:Range

The internal range use to defined the days as text in the DateFormatter.

RANGE_HOURConstant 
public static const RANGE_HOUR:Range

The internal range use to defined the hours in the DateFormatter.

RANGE_MILLISECONDConstant 
public static const RANGE_MILLISECOND:Range

The internal range use to defined the milliseconds in the DateFormatter.

RANGE_MINUTEConstant 
public static const RANGE_MINUTE:Range

The internal range use to defined the minutes in the DateFormatter.

RANGE_MONTHConstant 
public static const RANGE_MONTH:Range

The internal range use to defined the months in the DateFormatter.

RANGE_SECONDConstant 
public static const RANGE_SECOND:Range

The internal range use to defined the seconds in the DateFormatter.

SECONDConstant 
public static const SECOND:String = s

Placeholder for second in minute in date format.

YEARConstant 
public static const YEAR:String = y

Placeholder for year in date format.