Class DateFormat

Description

DateFormat class.

The DateFormat class allows you to format dates and times with predefined styles in a locale-sensitive manner. Formatting times with the DateFormat class is similar to formatting dates.

Formatting dates with the DateFormat class is a two-step process. First, you create a formatter with the getDateInstance method. Second, you invoke the format method, which returns a string containing the formatted date.

DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo.

Located in /I18N/core/DateFormat.php (line 48)


	
			
Variable Summary
Method Summary
DateFormat __construct ([mixed $formatInfo = null])
string format (mixed $time, [mixed $pattern = 'F'], [mixed $charset = 'UTF-8'])
string getAMPM (array $date, [string $pattern = 'a'])
string getDay (array $date, [string $pattern = 'd'])
int getDayInMonth (array $date, [string $pattern = 'FF'])
string getDayInWeek (array $date, [string $pattern = 'EEEE'])
int getDayInYear (array $date, [string $pattern = 'D'])
string getEra (array $date, [string $pattern = 'G'])
mixed getFunctionName (string $token)
string getHour12 (array $date, [string $pattern = 'h'])
string getHour24 (array $date, [string $pattern = 'H'])
int getHourInAMPM (array $date, [string $pattern = 'K'])
int getHourInDay (array $date, [string $pattern = 'k'])
string getMinutes (array $date, [string $pattern = 'm'])
string getMonth (array $date, [string $pattern = 'M'])
string getPattern (mixed $pattern)
string getSeconds (array $date, [string $pattern = 's'])
string getTimeZone (array $date, [string $pattern = 'z'])
array getTokens (string $pattern)
int getWeekInMonth (array $date, [mixed $pattern = 'W'])
int getWeekInYear (array $date, [string $pattern = 'w'])
string getYear (array $date, [string $pattern = 'yyyy'])
Variables
DateTimeFormatInfo $formatInfo (line 84)

The DateTimeFormatInfo, containing culture specific patterns and names.

  • access: protected
array $methods = array() (line 78)

A list of methods, to be used by the token function calls.

  • access: protected
array $tokens = array(
'G'=>'Era',
'y'=>'Year',
'M'=>'Month',
'd'=>'Day',
'h'=>'Hour12',
'H'=>'Hour24',
'm'=>'Minutes',
's'=>'Seconds',
'E'=>'DayInWeek',
'D'=>'DayInYear',
'F'=>'DayInMonth',
'w'=>'WeekInYear',
'W'=>'WeekInMonth',
'a'=>'AMPM',
'k'=>'HourInDay',
'K'=>'HourInAMPM',
'z'=>'TimeZone'
)
(line 54)

A list of tokens and their function call.

  • access: protected
Methods
Constructor __construct (line 92)

Initialize a new DateFormat.

  • return: instance
DateFormat __construct ([mixed $formatInfo = null])
  • mixed $formatInfo: either, null, a CultureInfo instance, a DateTimeFormatInfo instance, or a locale.
format (line 111)

Format a date according to the pattern.

  • return: formatted date time.
  • access: public
string format (mixed $time, [mixed $pattern = 'F'], [mixed $charset = 'UTF-8'])
  • mixed $time: the time as integer or string in strtotime format.
getAMPM (line 464)

Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.

  • return: AM or PM designator
  • access: protected
string getAMPM (array $date, [string $pattern = 'a'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getDay (line 398)

Get the day of the month.

"d" for non-padding, "dd" will always return 2 characters.

  • return: day of the month
  • access: protected
string getDay (array $date, [string $pattern = 'd'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getDayInMonth (line 577)

Get day in the month.

  • return: day in month
  • access: protected
int getDayInMonth (array $date, [string $pattern = 'FF'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getDayInWeek (line 368)

Get the day of the week.

"E" will return integer 0 (for Sunday) through 6 (for Saturday). "EE" will return the narrow day of the week, e.g. "M" "EEE" will return the abrreviated day of the week, e.g. "Mon" "EEEE" will return the day of the week, e.g. "Monday"

  • return: day of the week.
  • access: protected
string getDayInWeek (array $date, [string $pattern = 'EEEE'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getDayInYear (line 563)

Get the day in the year, e.g. [1-366]

  • return: hours in AM/PM format.
  • access: protected
int getDayInYear (array $date, [string $pattern = 'D'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getEra (line 422)

Get the era. i.e. in gregorian, year > 0 is AD, else BC.

  • return: era
  • access: protected
  • todo: How to support multiple Eras?, e.g. Japanese.
string getEra (array $date, [string $pattern = 'G'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getFunctionName (line 164)

For a particular token, get the corresponding function to call.

  • return: the function if good token, null otherwise.
  • access: protected
mixed getFunctionName (string $token)
  • string $token: token
getHour12 (line 481)

Get the hours in 12 hour format.

"h" for non-padding, "hh" will always return 2 characters.

  • return: hours in 12 hour format.
  • access: protected
string getHour12 (array $date, [string $pattern = 'h'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getHour24 (line 442)

Get the hours in 24 hour format, i.e. [0-23].

"H" for non-padding, "HH" will always return 2 characters.

  • return: hours in 24 hour format.
  • access: protected
string getHour24 (array $date, [string $pattern = 'H'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getHourInAMPM (line 638)

Get the hours in AM/PM format, e.g [1-12]

  • return: hours in AM/PM format.
  • access: protected
int getHourInAMPM (array $date, [string $pattern = 'K'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getHourInDay (line 624)

Get the hours [1-24].

  • return: hours [1-24]
  • access: protected
int getHourInDay (array $date, [string $pattern = 'k'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getMinutes (line 505)

Get the minutes.

"m" for non-padding, "mm" will always return 2 characters.

  • return: minutes.
  • access: protected
string getMinutes (array $date, [string $pattern = 'm'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getMonth (line 337)

Get the month.

"M" will return integer 1 through 12 "MM" will return the narrow month name, e.g. "J" "MMM" will return the abrreviated month name, e.g. "Jan" "MMMM" will return the month name, e.g. "January"

  • return: month name
  • access: protected
string getMonth (array $date, [string $pattern = 'M'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getPattern (line 181)

Get the pattern from DateTimeFormatInfo or some predefined patterns.

If the $pattern parameter is an array of 2 element, it will assume that the first element is the date, and second the time and try to find an appropriate pattern and apply DateTimeFormatInfo::formatDateTime See the tutorial documentation for futher details on the patterns.

string getPattern (mixed $pattern)
  • mixed $pattern: a pattern.
getSeconds (line 527)

Get the seconds.

"s" for non-padding, "ss" will always return 2 characters.

  • return: seconds
  • access: protected
string getSeconds (array $date, [string $pattern = 's'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getTimeZone (line 549)

Get the timezone from the server machine.

  • return: time zone
  • access: protected
  • todo: How to get the timezone for a different region?
string getTimeZone (array $date, [string $pattern = 'z'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getTokens (line 270)

Tokenize the pattern. The tokens are delimited by group of similar characters, e.g. 'aabb' will form 2 tokens of 'aa' and 'bb'.

Any substrings, starting and ending with a single quote (') will be treated as a single token.

  • return: string tokens in an array.
  • access: protected
array getTokens (string $pattern)
  • string $pattern: pattern.
getWeekInMonth (line 610)

Get week in the month.

  • return: week in month
  • access: protected
int getWeekInMonth (array $date, [mixed $pattern = 'W'])
  • array $date: getdate format.
getWeekInYear (line 597)

Get the week in the year.

  • return: week in year
  • access: protected
int getWeekInYear (array $date, [string $pattern = 'w'])
  • array $date: getdate format.
  • string $pattern: a pattern.
getYear (line 313)

Get the year.

"yy" will return the last two digits of year. "yyyy" will return the full integer year.

  • return: year
  • access: protected
string getYear (array $date, [string $pattern = 'yyyy'])
  • array $date: getdate format.
  • string $pattern: a pattern.

Documentation generated on Sun, 04 Jun 2006 18:58:24 -0400 by phpDocumentor 1.3.0RC4