W3cubDocs

/Symfony 4.1

IntlDateFormatter

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

Properties

protected int $errorCode The error code from the last operation.
protected string $errorMessage The error message from the last operation.

Methods

__construct(string|null $locale, int $datetype, int $timetype, mixed $timezone = null, int|null $calendar = self::GREGORIAN, string $pattern = null)
static IntlDateFormatter create(string $locale, int $datetype, int $timetype, string $timezone = null, int $calendar = self::GREGORIAN, string $pattern = null)

Static constructor.

string|bool format(int|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 U_ZERO_ERROR class constant value.

string getErrorMessage()

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

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

Returns the formatter's locale.

string getPattern()

Returns the formatter's pattern.

int getTimeType()

Returns the formatter's time type.

string getTimeZoneId()

Returns the formatter's timezone identifier.

mixed getTimeZone()

Not supported. Returns the formatter's timezone.

bool isLenient()

Returns whether the formatter is lenient.

string localtime(string $value, int $position = 0)

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

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

Parse string to a timestamp value.

bool setCalendar(string $calendar)

Not supported. Set the formatter's calendar.

bool setLenient(bool $lenient)

Set the leniency of the parser.

bool setPattern(string $pattern)

Set the formatter's pattern.

bool setTimeZoneId(string $timeZoneId)

Set the formatter's timezone identifier.

bool setTimeZone(mixed $timeZone)

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

DateTime createDateTime(int $timestamp)

Create and returns a DateTime object with the specified timestamp and with the current time zone.

string getDefaultPattern()

Returns a pattern string based in the datetype and timetype values.

Details

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

Parameters

string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "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
mixed $timezone Timezone identifier
int|null $calendar Calendar to use for formatting or parsing. The only currently supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
string $pattern Optional pattern to use when formatting

Exceptions

MethodArgumentValueNotImplementedException When $locale different than "en" or null 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

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" (or null using the default locale, i.e. "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" or null 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

string|bool format(int|DateTime $timestamp)

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

Parameters

int|DateTime $timestamp The timestamp to format

Return Value

string|bool 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

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

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

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

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

int getErrorCode()

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

Return Value

int The error code from last formatter call

See also

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

string getErrorMessage()

Returns formatter's last error message. Always returns the U_ZERO_ERROR_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

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

Returns the formatter's locale.

Parameters

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

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

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

int getTimeType()

Returns the formatter's time type.

Return Value

int The time type used by the formatter

See also

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

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

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

bool isLenient()

Returns whether the formatter is lenient.

Return Value

bool Currently always returns false

Exceptions

MethodNotImplementedException

See also

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

string localtime(string $value, int $position = 0)

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, $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

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

int 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, $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

int 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

bool setCalendar(string $calendar)

Not supported. Set the formatter's calendar.

Parameters

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

Return Value

bool true on success or false on failure

Exceptions

MethodNotImplementedException

See also

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

bool setLenient(bool $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

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

Return Value

bool true on success or false on failure

Exceptions

MethodArgumentValueNotImplementedException When $lenient is true

See also

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

bool setPattern(string $pattern)

Set the formatter's pattern.

Parameters

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

Return Value

bool 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

bool 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

bool true on success or false on failure

See also

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

bool setTimeZone(mixed $timeZone)

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

Parameters

mixed $timeZone

Return Value

bool true on success or false on failure

See also

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

protected DateTime createDateTime(int $timestamp)

Create and returns a DateTime object with the specified timestamp and with the current time zone.

Parameters

int $timestamp

Return Value

DateTime

protected string getDefaultPattern()

Returns a pattern string based in the datetype and timetype values.

Return Value

string

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.html