Back to index

php5  5.3.10
Public Member Functions | Static Public Member Functions | Public Attributes
DateFormatter Class Reference

Date Formatter class - locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns. More...

List of all members.

Public Member Functions

 __construct ($locale, $datetype, $timetype, $timezone=null, $calendar=null, $pattern=null)
 Create a date formatter.
 format ($value)
 formats the time value as a string.
 parse ($value, $parse_pos=0)
 converts string $value to an incremental time value, starting at $parse_pos and consuming as much of the input value as possible If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred).
 localtime ($value, $parse_pos=0)
 converts string $value to a field-based time value, starting at $parse_pos and consuming as much of the input value as possible If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred).
 getDateType ()
 Gets the datetype in use.
 getTimeType ()
 Gets the timetype in use.
 isLenient ()
 Gets the leniency in use.
 setLenient ($lenient)
 Sets the leniency to use.
 getLocale ($type=ULOC_ACTUAL_LOCALE)
 Gets the locale in use.
 getTimeZoneId ()
 setTimeZoneId ($zone)
 sets the time zone to use
 setCalendar ($which)
 Sets the calendar used to the appropriate calendar, which must be one of the constants defined above.
 getCalendar ()
 Gets the Calendar in use.
 getPattern ()
 Gets the pattern in use.
 setPattern ($pattern)
 Sets the pattern to use.
 getErrorCode ()
 Get the error code from last operation.
 getErrorMessage ()
 Get the error text from the last operation.

Static Public Member Functions

static create ($locale, $datetype, $timetype, $timezone=null, $calendar=null, $pattern=null)
 Create a date formatter.

Public Attributes

const NONE = -1
 The following constants are used to specify different formats in the constructor.
const FULL = 0
const LONG = 1
const MEDIUM = 2
const SHORT = 3
const TRADITIONAL = 0
 The following int constants are used to specify the calendar.
const GREGORIAN = 1

Detailed Description

Date Formatter class - locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns.

This class represents the ICU date formatting functionality. It allows users to display dates in a localized format or to parse strings into PHP date values using pattern strings and/or canned patterns.

Example: $datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get()); echo $formatter->format(time());

$datefmt = new DateFormatter("de-DE", LONG, SHORT, date_default_timezone_get() , GREGORIAN , "yyyy-MM-dd HH:mm:ss z"); echo $formatter->format(time());

See also:
http://www.icu-project.org/apiref/icu4c/udat_8h.html

Definition at line 24 of file datefmt_api.php.


Constructor & Destructor Documentation

DateFormatter::__construct ( locale,
datetype,
timetype,
timezone = null,
calendar = null,
pattern = null 
)

Create a date formatter.

Parameters:
string$localeLocale to use when formatting or parsing
integer$datetypeDate type to use (none, short, medium, long, full)
integer$timetypeTime type to use (none, short, medium, long, full)
[String]$timezone Time zone ID ; default is system default
[integer]$calendar Calendar to use for formatting or parsing; default is GREGORIAN
[string]$pattern Optional pattern to use when formatting or parsing
Returns:
DateFormatter
See also:
__construct
datefmt_create

Definition at line 66 of file datefmt_api.php.

{}

Member Function Documentation

static DateFormatter::create ( locale,
datetype,
timetype,
timezone = null,
calendar = null,
pattern = null 
) [static]

Create a date formatter.

Parameters:
string$localeLocale to use when formatting or parsing
integer$datetypeDate type to use (none, short, medium, long, full)
integer$timetypeTime type to use (none, short, medium, long, full)
[string]$timezone Time zone ID ; default is system default
[integer]$calendar Calendar to use for formatting or parsing; default is GREGORIAN
[string]$pattern Optional pattern to use when formatting or parsing
Returns:
DateFormatter
See also:
__construct
datefmt_create

Definition at line 82 of file datefmt_api.php.

{}
DateFormatter::format ( value)

formats the time value as a string.

Parameters:
mixed$value- value to format integer: a unix timestamp value (seconds since epoch, UTC) array: a localtime array - uses 24 hour clock in tm_hour field
Returns:
string a formatted string or, if an error occurred, 'null'.

Definition at line 91 of file datefmt_api.php.

{}

Gets the Calendar in use.

Returns:
integer the calendar being used by the formatter

Definition at line 205 of file datefmt_api.php.

{}

Gets the datetype in use.

Returns:
integer the current 'datetype' value of the formatter

Definition at line 128 of file datefmt_api.php.

{}

Get the error code from last operation.

Returns error code from the last number formatting operation.

Returns:
integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

Definition at line 231 of file datefmt_api.php.

{}

Get the error text from the last operation.

Returns:
string Description of the last error.

Definition at line 239 of file datefmt_api.php.

{}
DateFormatter::getLocale ( type = ULOC_ACTUAL_LOCALE)

Gets the locale in use.

Parameters:
[integer]which locale should be returned? values may include ULOC_ACTUAL_LOCALE, ULOC_VALID_LOCALE. By default the actual locale is returned.
Returns:
string the locale of this formatter or 'false' if error

Definition at line 169 of file datefmt_api.php.

{}

Gets the pattern in use.

Returns:
string the pattern string being used to format/parse

Definition at line 212 of file datefmt_api.php.

{}

Gets the timetype in use.

Returns:
integer the current 'timetype' value of the formatter

Definition at line 135 of file datefmt_api.php.

{}
Returns:
string ID string for the time zone used by this formatter

Definition at line 175 of file datefmt_api.php.

{}

Gets the leniency in use.

Returns:
boolean 'true' if parser is lenient, 'false' if parser is strict default value for parser is 'false'.

Definition at line 143 of file datefmt_api.php.

{}
DateFormatter::localtime ( value,
parse_pos = 0 
)

converts string $value to a field-based time value, starting at $parse_pos and consuming as much of the input value as possible If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred).

Parameters:
string$valuestring to convert to a time
integer$parse_posposition at which to start the parsing in $value (zero-based) This variable will contain the end position if the parse fails If $parse_pos > strlen($value), the parse fails immediately.
Returns:
array localtime compatible array of integers - uses 24 hour clock in tm_hour field

Definition at line 121 of file datefmt_api.php.

{}
DateFormatter::parse ( value,
parse_pos = 0 
)

converts string $value to an incremental time value, starting at $parse_pos and consuming as much of the input value as possible If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred).

Parameters:
string$valuestring to convert to a time
integer$parse_posposition at which to start the parsing in $value (zero-based) This variable will contain the end position if the parse fails If $parse_pos > strlen($value), the parse fails immediately.
Returns:
integer timestamp parsed value

Definition at line 106 of file datefmt_api.php.

{}

Sets the calendar used to the appropriate calendar, which must be one of the constants defined above.

Some examples include:

  • Gregorian calendar
  • Traditional Default value is GREGORIAN
    Parameters:
    integer$whichthe calendar (an enumerated constant) to use.
    Returns:
    boolean 'true' if successful, 'false' if an error occurred or if the calendar was not recognized

Definition at line 198 of file datefmt_api.php.

{}
DateFormatter::setLenient ( lenient)

Sets the leniency to use.

Parameters:
boolean$lenientsets whether the parser is lenient or not, default is 'false' 'true' sets the parser to accept otherwise flawed date or time patterns, parsing as much as possible to obtain a value. 'false' sets the parser to strictly parse strings into dates. Extra space, unrecognized tokens, or invalid values ("Feburary 30th") are not accepted.
Returns:
boolean 'true' if successful; 'false' if an error occurred.

Definition at line 157 of file datefmt_api.php.

{}
DateFormatter::setPattern ( pattern)

Sets the pattern to use.

Parameters:
string$patternnew pattern string to use
Returns:
boolean 'true' if successful, 'false' if an error occured. Bad format strings are usually the cause of the latter.

Definition at line 221 of file datefmt_api.php.

{}

sets the time zone to use

Parameters:
string$zonezone ID string of the time zone to use. if null or the empty string, the default time zone for the runtime is used.
Returns:
boolean 'true' on successful setting of the time zone, 'false' if an error occurred (such as the time zone wasn't recognized).

Definition at line 186 of file datefmt_api.php.

{}

Member Data Documentation

Definition at line 35 of file datefmt_api.php.

Definition at line 47 of file datefmt_api.php.

Definition at line 36 of file datefmt_api.php.

Definition at line 37 of file datefmt_api.php.

const DateFormatter::NONE = -1

The following constants are used to specify different formats in the constructor.

Definition at line 34 of file datefmt_api.php.

Definition at line 38 of file datefmt_api.php.

The following int constants are used to specify the calendar.

These calendars are all based directly on the Gregorian calendar Non-Gregorian calendars need to be specified in locale. Examples might include locale="hi@calendar=BUDDHIST"

Definition at line 46 of file datefmt_api.php.


The documentation for this class was generated from the following file: