class IntlDateFormatter

Replacement for PHP's native {@link \IntlDateFormatter} class.

The only methods currently supported in this class are:

  • {@link __construct}
  • {@link create}
  • {@link format}
  • {@link getCalendar}
  • {@link getDateType}
  • {@link getErrorCode}
  • {@link getErrorMessage}
  • {@link getLocale}
  • {@link getPattern}
  • {@link getTimeType}
  • {@link getTimeZoneId}
  • {@link isLenient}
  • {@link parse}
  • {@link setLenient}
  • {@link setPattern}
  • {@link setTimeZoneId}
  • {@link setTimeZone}

Constants

NONE

FULL

LONG

MEDIUM

SHORT

TRADITIONAL

GREGORIAN

Methods

__construct(string $locale, int $datetype, int $timetype, string $timezone = null, int $calendar = self::GREGORIAN, string $pattern = null)

Constructor

create(string $locale, int $datetype, int $timetype, string $timezone = null, int $calendar = self::GREGORIAN, string $pattern = null)

Static constructor

string|Boolean
format(integer|DateTime $timestamp)

Format the date/time value (timestamp) as a string

string
formatObject(object $object, mixed $format = null, string $locale = null)

Not supported. Formats an object

int
getCalendar()

Returns the formatter's calendar

object
getCalendarObject()

Not supported. Returns the formatter's calendar object

int
getDateType()

Returns the formatter's datetype

int
getErrorCode()

Returns formatter's last error code. Always returns the UZEROERROR class constant value

string
getErrorMessage()

Returns formatter's last error message. Always returns the UZEROERROR_MESSAGE class constant value

string
getLocale(int $type = Locale::ACTUAL_LOCALE)

Returns the formatter's locale

string
getPattern()

Returns the formatter's pattern

string
getTimeType()

Returns the formatter's time type

string
getTimeZoneId()

Returns the formatter's timezone identifier

mixed
getTimeZone()

Not supported. Returns the formatter's timezone

Boolean
isLenient()

Returns whether the formatter is lenient

string
localtime(string $value, int $position)

Not supported. Parse string to a field-based time value

string
parse(string $value, int $position = null)

Parse string to a timestamp value

Boolean
setCalendar(string $calendar)

Not supported. Set the formatter's calendar

Boolean
setLenient(Boolean $lenient)

Set the leniency of the parser

Boolean
setPattern(string $pattern)

Set the formatter's pattern

Boolean
setTimeZoneId(string $timeZoneId)

Set the formatter's timezone identifier

Boolean
setTimeZone(mixed $timeZone)

This method was added in PHP 5.5 as replacement for setTimeZoneId()

Details

at line line 146
__construct(string $locale, int $datetype, int $timetype, string $timezone = null, int $calendar = self::GREGORIAN, string $pattern = null)

Constructor

Parameters

string $locale The locale code. The only currently supported locale is "en".
int $datetype Type of date formatting, one of the format type constants
int $timetype Type of time formatting, one of the format type constants
string $timezone Timezone identifier
int $calendar Calendar to use for formatting or parsing. The only currently supported value is IntlDateFormatter::GREGORIAN.
string $pattern Optional pattern to use when formatting

Exceptions

MethodArgumentValueNotImplementedException When $locale different than "en" is passed
MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed

See also

http://www.php.net/manual/en/intldateformatter.create.php
http://userguide.icu-project.org/formatparse/datetime

at line line 182
static IntlDateFormatter create(string $locale, int $datetype, int $timetype, string $timezone = null, int $calendar = self::GREGORIAN, string $pattern = null)

Static constructor

Parameters

string $locale The locale code. The only currently supported locale is "en".
int $datetype Type of date formatting, one of the format type constants
int $timetype Type of time formatting, one of the format type constants
string $timezone Timezone identifier
int $calendar Calendar to use for formatting or parsing; default is Gregorian. One of the calendar constants.
string $pattern Optional pattern to use when formatting

Return Value

IntlDateFormatter

Exceptions

MethodArgumentValueNotImplementedException When $locale different than "en" is passed
MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed

See also

http://www.php.net/manual/en/intldateformatter.create.php
http://userguide.icu-project.org/formatparse/datetime

at line line 199
string|Boolean format(integer|DateTime $timestamp)

Format the date/time value (timestamp) as a string

Parameters

integer|DateTime $timestamp The timestamp to format. \DateTime objects are supported as of PHP 5.3.4.

Return Value

string|Boolean The formatted value or false if formatting failed.

Exceptions

MethodArgumentValueNotImplementedException If one of the formatting characters is not implemented

See also

http://www.php.net/manual/en/intldateformatter.format.php

at line line 258
string formatObject(object $object, mixed $format = null, string $locale = null)

Not supported. Formats an object

Parameters

object $object
mixed $format
string $locale

Return Value

string The formatted value

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.formatobject.php

at line line 271
int getCalendar()

Returns the formatter's calendar

Return Value

int The calendar being used by the formatter. Currently always returns IntlDateFormatter::GREGORIAN.

See also

http://www.php.net/manual/en/intldateformatter.getcalendar.php

at line line 285
object getCalendarObject()

Not supported. Returns the formatter's calendar object

Return Value

object The calendar's object being used by the formatter

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.getcalendarobject.php

at line line 297
int getDateType()

Returns the formatter's datetype

Return Value

int The current value of the formatter

See also

http://www.php.net/manual/en/intldateformatter.getdatetype.php

at line line 309
int getErrorCode()

Returns formatter's last error code. Always returns the UZEROERROR class constant value

Return Value

int The error code from last formatter call

See also

http://www.php.net/manual/en/intldateformatter.geterrorcode.php

at line line 321
string getErrorMessage()

Returns formatter's last error message. Always returns the UZEROERROR_MESSAGE class constant value

Return Value

string The error message from last formatter call

See also

http://www.php.net/manual/en/intldateformatter.geterrormessage.php

at line line 336
string getLocale(int $type = Locale::ACTUAL_LOCALE)

Returns the formatter's locale

Parameters

int $type Not supported. The locale name type to return (Locale::VALIDLOCALE or Locale::ACTUALLOCALE)

Return Value

string The locale used to create the formatter. Currently always returns "en".

See also

http://www.php.net/manual/en/intldateformatter.getlocale.php

at line line 348
string getPattern()

Returns the formatter's pattern

Return Value

string The pattern string used by the formatter

See also

http://www.php.net/manual/en/intldateformatter.getpattern.php

at line line 360
string getTimeType()

Returns the formatter's time type

Return Value

string The time type used by the formatter

See also

http://www.php.net/manual/en/intldateformatter.gettimetype.php

at line line 372
string getTimeZoneId()

Returns the formatter's timezone identifier

Return Value

string The timezone identifier used by the formatter

See also

http://www.php.net/manual/en/intldateformatter.gettimezoneid.php

at line line 395
mixed getTimeZone()

Not supported. Returns the formatter's timezone

Return Value

mixed The timezone used by the formatter

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.gettimezone.php

at line line 409
Boolean isLenient()

Returns whether the formatter is lenient

Return Value

Boolean Currently always returns false.

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.islenient.php

at line line 429
string localtime(string $value, int $position)

Not supported. Parse string to a field-based time value

Parameters

string $value String to convert to a time value
int $position Position at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parsepos will contain -1 otherwise it will contain the position at which parsing ended. If $parsepos > strlen($value), the parse fails immediately.

Return Value

string Localtime compatible array of integers: contains 24 hour clock value in tm_hour field

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.localtime.php

at line line 449
string parse(string $value, int $position = null)

Parse string to a timestamp value

Parameters

string $value String to convert to a time value
int $position Not supported. Position at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parsepos will contain -1 otherwise it will contain the position at which parsing ended. If $parsepos > strlen($value), the parse fails immediately.

Return Value

string Parsed value as a timestamp

Exceptions

MethodArgumentNotImplementedException When $position different than null, behavior not implemented

See also

http://www.php.net/manual/en/intldateformatter.parse.php

at line line 479
Boolean setCalendar(string $calendar)

Not supported. Set the formatter's calendar

Parameters

string $calendar The calendar to use. Default is IntlDateFormatter::GREGORIAN.

Return Value

Boolean true on success or false on failure

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/intldateformatter.setcalendar.php

at line line 501
Boolean setLenient(Boolean $lenient)

Set the leniency of the parser

Define if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly. Enabling lenient parsing allows the parser to accept otherwise flawed date or time patterns, parsing as much as possible to obtain a value. Extra space, unrecognized tokens, or invalid values ("February 30th") are not accepted.

Parameters

Boolean $lenient Sets whether the parser is lenient or not. Currently only false (strict) is supported.

Return Value

Boolean true on success or false on failure

Exceptions

MethodArgumentValueNotImplementedException When $lenient is true

See also

http://www.php.net/manual/en/intldateformatter.setlenient.php

at line line 520
Boolean setPattern(string $pattern)

Set the formatter's pattern

Parameters

string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation

Return Value

Boolean true on success or false on failure

See also

http://www.php.net/manual/en/intldateformatter.setpattern.php
http://userguide.icu-project.org/formatparse/datetime

at line line 542
Boolean setTimeZoneId(string $timeZoneId)

Set the formatter's timezone identifier

Parameters

string $timeZoneId The time zone ID string of the time zone to use. If NULL or the empty string, the default time zone for the runtime is used.

Return Value

Boolean true on success or false on failure

See also

http://www.php.net/manual/en/intldateformatter.settimezoneid.php

at line line 591
Boolean setTimeZone(mixed $timeZone)

This method was added in PHP 5.5 as replacement for setTimeZoneId()

Parameters

mixed $timeZone

Return Value

Boolean true on success or false on failure

See also

http://www.php.net/manual/en/intldateformatter.settimezone.php