class IntlDateFormatter (View source)

Constants

FULL

Completely specified style (Tuesday, April 12, 1952 AD or 3:30:42pm PST)

LONG

Long style (January 12, 1952 or 3:30:32pm)

MEDIUM

Medium style (Jan 12, 1952)

SHORT

Most abbreviated style, only essential data (12/13/52 or 3:30pm)

NONE

Do not include this element

GREGORIAN

Gregorian Calendar

TRADITIONAL

Non-Gregorian Calendar

RELATIVE_FULL

RELATIVE_LONG

RELATIVE_MEDIUM

RELATIVE_SHORT

PATTERN

Methods

__construct(string|null $locale, int $dateType = 0, int $timeType = 0, mixed|null $timezone = null, mixed|null $calendar = null, string $pattern = null)

No description

static IntlDateFormatter|null
create(string $locale, int $dateType = 0, int $timeType = 0, string $timezone = null, int $calendar = null, string $pattern = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Create a date formatter

int|false
getDateType()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the datetype used for the IntlDateFormatter

int|false
getTimeType()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the timetype used for the IntlDateFormatter

int|false
getCalendar()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the calendar used for the IntlDateFormatter

bool
setCalendar(int $calendar)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
sets the calendar used to the appropriate calendar, which must be

string|false
getTimeZoneId()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the timezone-id used for the IntlDateFormatter

IntlCalendar|false|null
getCalendarObject()

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Get copy of formatter's calendar object

IntlTimeZone|false
getTimeZone()

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Get formatter's timezone

bool
setTimeZoneId(string $zone)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Sets the time zone to use

bool|null
setTimeZone(mixed $timezone)

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Sets formatter's timezone

bool
setPattern(string $pattern)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Set the pattern used for the IntlDateFormatter

string|false
getPattern()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the pattern used for the IntlDateFormatter

string|false
getLocale(int $type = 0)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the locale used by formatter

void
setLenient(bool $lenient)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Set the leniency of the parser

bool
isLenient()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the lenient used for the IntlDateFormatter

string|false
format(mixed $datetime, $array = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Format the date/time value as a string

static string|false
formatObject(object $datetime, mixed $format = null, string|null $locale = null)

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Formats an object

int|float|false
parse(string $string, int $offset = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Parse string to a timestamp value

array|false
localtime(string $string, int $offset = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Parse string to a field-based time value

int
getErrorCode()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the error code from last operation

string
getErrorMessage()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the error text from the last operation.

int|float|false
parseToCalendar(string $string, $offset = null)

No description

Details

__construct(string|null $locale, int $dateType = 0, int $timeType = 0, mixed|null $timezone = null, mixed|null $calendar = null, string $pattern = null)

No description

Parameters

string|null $locale
int $dateType
int $timeType
mixed|null $timezone [optional]
mixed|null $calendar [optional]
string $pattern [optional]

static IntlDateFormatter|null create(string $locale, int $dateType = 0, int $timeType = 0, string $timezone = null, int $calendar = null, string $pattern = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Create a date formatter

Parameters

string $locale

Locale to use when formatting or parsing; default is specified in the ini setting intl.default_locale.

int $dateType

Date type to use (none, short, medium, long, full). This is one of the IntlDateFormatter constants.

int $timeType

Time type to use (none, short, medium, long, full). This is one of the IntlDateFormatter constants.

string $timezone

[optional]

Time zone ID, default is system default.

int $calendar

[optional]

Calendar to use for formatting or parsing; default is Gregorian. This is one of the IntlDateFormatter calendar constants.

string $pattern

[optional]

Optional pattern to use when formatting or parsing. Possible patterns are documented at http://userguide.icu-project.org/formatparse/datetime.

Return Value

IntlDateFormatter|null

int|false getDateType()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the datetype used for the IntlDateFormatter

Return Value

int|false

The current date type value of the formatter.

int|false getTimeType()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the timetype used for the IntlDateFormatter

Return Value

int|false

The current date type value of the formatter.

int|false getCalendar()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the calendar used for the IntlDateFormatter

Return Value

int|false

The calendar being used by the formatter.

bool setCalendar(int $calendar)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
sets the calendar used to the appropriate calendar, which must be

Parameters

int $calendar

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

Return Value

bool

TRUE on success or FALSE on failure.

string|false getTimeZoneId()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the timezone-id used for the IntlDateFormatter

Return Value

string|false

ID string for the time zone used by this formatter.

IntlCalendar|false|null getCalendarObject()

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Get copy of formatter's calendar object

Return Value

IntlCalendar|false|null

A copy of the internal calendar object used by this formatter.

IntlTimeZone|false getTimeZone()

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Get formatter's timezone

Return Value

IntlTimeZone|false

The associated IntlTimeZone object or FALSE on failure.

bool setTimeZoneId(string $zone)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Sets the time zone to use

Parameters

string $zone

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

bool

TRUE on success or FALSE on failure.

See also

IntlDateFormatter::setTimeZone

bool|null setTimeZone(mixed $timezone)

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Sets formatter's timezone

Parameters

mixed $timezone

The timezone to use for this formatter. This can be specified in the following forms:

  • NULL, in which case the default timezone will be used, as specified in the ini setting "https://secure.php.net/manual/en/datetime.configuration.php#ini.date.timezone" date.timezone or through the function "https://secure.php.net/manual/en/function.date-default-timezone-set.php" date_default_timezone_set() and as returned by "https://secure.php.net/manual/en/function.date-default-timezone-get.php" date_default_timezone_get().

  • An "https://secure.php.net/manual/en/class.intltimezone.php" IntlTimeZone, which will be used directly.

  • A "https://secure.php.net/manual/en/class.datetimezone.php" DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICU's database, not PHP's.

  • A "https://secure.php.net/manual/en/language.types.string.php" string, which should be a valid ICU timezone identifier. See IntlTimeZone::createTimeZoneIDEnumeration(). Raw offsets such as "GMT+08:30" are also accepted.

Return Value

bool|null

TRUE on success or FALSE on failure.

bool setPattern(string $pattern)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Set the pattern used for the IntlDateFormatter

Parameters

string $pattern

New pattern string to use. Possible patterns are documented at http://userguide.icu-project.org/formatparse/datetime.

Return Value

bool

TRUE on success or FALSE on failure. Bad formatstrings are usually the cause of the failure.

string|false getPattern()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the pattern used for the IntlDateFormatter

Return Value

string|false

The pattern string being used to format/parse.

string|false getLocale(int $type = 0)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the locale used by formatter

Parameters

int $type [optional]

Return Value

string|false

the locale of this formatter or 'false' if error

void setLenient(bool $lenient)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Set the leniency of the parser

Parameters

bool $lenient

Sets whether the parser is lenient or not, default is TRUE (lenient).

Return Value

void

bool isLenient()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the lenient used for the IntlDateFormatter

Return Value

bool

TRUE if parser is lenient, FALSE if parser is strict. By default the parser is lenient.

string|false format(mixed $datetime, $array = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Format the date/time value as a string

Parameters

mixed $datetime

Value to format. This may be a DateTime object, an integer representing a Unix timestamp value (seconds since epoch, UTC) or an array in the format output by localtime.

$array

Return Value

string|false

The formatted string or, if an error occurred, FALSE.

static string|false formatObject(object $datetime, mixed $format = null, string|null $locale = null)

(PHP 5 >= 5.5.0, PECL intl >= 3.0.0)
Formats an object

Parameters

object $datetime

An object of type "https://secure.php.net/manual/en/class.intlcalendar.php" IntlCalendar} or {@link "https://secure.php.net/manual/en/class.datetime.php" DateTime. The timezone information in the object will be used.

mixed $format

[optional]

How to format the date/time. This can either be an "https://secure.php.net/manual/en/language.types.array.php" array with two elements (first the date style, then the time style, these being one of the constants IntlDateFormatter::NONE, IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG, IntlDateFormatter::FULL), a long with the value of one of these constants (in which case it will be used both for the time and the date) or a "https://secure.php.net/manual/en/language.types.string.php" string with the format described in "http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details" the ICU documentation. If NULL, the default style will be used.

string|null $locale

[optional]

The locale to use, or NULL to use the "https://secure.php.net/manual/en/intl.configuration.php#ini.intl.default-locale" default one.

Return Value

string|false

A string with result or FALSE on failure.

int|float|false parse(string $string, int $offset = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Parse string to a timestamp value

Parameters

string $string

string to convert to a time

int $offset

[optional]

Position at which to start the parsing in $value (zero-based). 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). This variable will contain the end position if the parse fails. If $parse_pos > strlen($value), the parse fails immediately.

Return Value

int|float|false

timestamp parsed value

array|false localtime(string $string, int $offset = null)

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Parse string to a field-based time value

Parameters

string $string

string to convert to a time

int $offset

[optional]

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

Return Value

array|false

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

int getErrorCode()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the error code from last operation

Return Value

int

The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

string getErrorMessage()

(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
Get the error text from the last operation.

Return Value

string

Description of the last error.

int|float|false parseToCalendar(string $string, $offset = null)

Since: 8.4

No description

Parameters

string $string
$offset

Return Value

int|float|false