System.I18N.core
[ class tree: System.I18N.core ] [ index: System.I18N.core ] [ all elements ]

Class: DateFormat

Source Location: /I18N/core/DateFormat.php

Class Overview


DateFormat class.

Class Details

[line 48]
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.




version:  v1.0, last update on Sat Dec 04 14:10:49 EST 2004
author:  Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>


[ Top ]

Variables

Methods



Class Variables

$formatInfo =

[line 84]

The DateTimeFormatInfo, containing culture specific patterns and names.



access:  protected

Type:   DateTimeFormatInfo


[ Top ]

$methods = array()

[line 78]

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



access:  protected

Type:   array


[ Top ]

$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

Type:   array


[ Top ]



Class Methods


constructor __construct [line 92]

DateFormat __construct( [mixed $formatInfo = null])

Initialize a new DateFormat.



return:  instance


Parameters:

mixed   $formatInfo   either, null, a CultureInfo instance, a DateTimeFormatInfo instance, or a locale.

[ Top ]

method format [line 111]

string format( mixed $time, [mixed $pattern = 'F'], [mixed $charset = 'UTF-8'])

Format a date according to the pattern.



return:  formatted date time.
access:  public


Parameters:

mixed   $time   the time as integer or string in strtotime format.

[ Top ]

method getAMPM [line 458]

string getAMPM( array $date, [string $pattern = 'a'])

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



return:  AM or PM designator
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getDay [line 392]

string getDay( array $date, [string $pattern = 'd'])

Get the day of the month.

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




return:  day of the month
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getDayInMonth [line 571]

int getDayInMonth( array $date, [string $pattern = 'FF'])

Get day in the month.



return:  day in month
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getDayInWeek [line 362]

string getDayInWeek( array $date, [string $pattern = 'EEEE'])

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


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getDayInYear [line 557]

int getDayInYear( array $date, [string $pattern = 'D'])

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



return:  hours in AM/PM format.
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getEra [line 416]

string getEra( array $date, [string $pattern = 'G'])

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.


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getFunctionName [line 159]

mixed getFunctionName( string $token)

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



return:  the function if good token, null otherwise.
access:  protected


Parameters:

string   $token   token

[ Top ]

method getHour12 [line 475]

string getHour12( array $date, [string $pattern = 'h'])

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


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getHour24 [line 436]

string getHour24( array $date, [string $pattern = 'H'])

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


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getHourInAMPM [line 635]

int getHourInAMPM( array $date, [string $pattern = 'K'])

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



return:  hours in AM/PM format.
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getHourInDay [line 618]

int getHourInDay( array $date, [string $pattern = 'k'])

Get the hours [1-24].



return:  hours [1-24]
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getMinutes [line 499]

string getMinutes( array $date, [string $pattern = 'm'])

Get the minutes.

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




return:  minutes.
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getMonth [line 331]

string getMonth( array $date, [string $pattern = 'M'])

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


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getPattern [line 176]

string getPattern( mixed $pattern)

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.




return:  a pattern.
access:  protected
see:  DateTimeFormatInfo::formatDateTime()


Parameters:

mixed   $pattern   a pattern.

[ Top ]

method getSeconds [line 521]

string getSeconds( array $date, [string $pattern = 's'])

Get the seconds.

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




return:  seconds
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getTimeZone [line 543]

string getTimeZone( array $date, [string $pattern = 'z'])

Get the timezone from the server machine.



return:  time zone
access:  protected
todo:  How to get the timezone for a different region?


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getTokens [line 265]

array getTokens( string $pattern)

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


Parameters:

string   $pattern   pattern.

[ Top ]

method getWeekInMonth [line 604]

int getWeekInMonth( array $date, [mixed $pattern = 'W'])

Get week in the month.



return:  week in month
access:  protected


Parameters:

array   $date   getdate format.

[ Top ]

method getWeekInYear [line 591]

int getWeekInYear( array $date, [string $pattern = 'w'])

Get the week in the year.



return:  week in year
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]

method getYear [line 307]

string getYear( array $date, [string $pattern = 'yyyy'])

Get the year.

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




return:  year
access:  protected


Parameters:

array   $date   getdate format.
string   $pattern   a pattern.

[ Top ]


© 2004-2005 PRADO Software Group. All Rights Reserved.