PHP Class yii\i18n\Formatter

The formatting methods provided by Formatter are all named in the form of asXyz(). The behavior of some of them may be configured via the properties of Formatter. For example, by configuring [[dateFormat]], one may control how Formatter::asDate formats the value into a date string. Formatter is configured as an application component in Application by default. You can access that instance via Yii::$app->formatter. The Formatter class is designed to format values according to a [[locale]]. For this feature to work the PHP intl extension has to be installed. Most of the methods however work also if the PHP intl extension is not installed by providing a fallback implementation. Without intl month and day names are in English only.
Since: 2.0
Author: Qiang Xue ([email protected])
Author: Enrica Ruedin ([email protected])
Author: Carsten Brandt ([email protected])
Inheritance: extends yii\base\Component
Datei anzeigen Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$booleanFormat the text to be displayed when formatting a boolean value. The first element corresponds to the text displayed for false, the second element for true. Defaults to ['No', 'Yes'], where Yes and No will be translated according to [[locale]].
$calendar the calendar to be used for date formatting. The value of this property will be directly passed to the constructor of the IntlDateFormatter class. Defaults to null, which means the Gregorian calendar will be used. You may also explicitly pass the constant \IntlDateFormatter::GREGORIAN for Gregorian calendar. To use an alternative calendar like for example the Jalali calendar, set this property to \IntlDateFormatter::TRADITIONAL. The calendar must then be specified in the [[locale]], for example for the persian calendar the configuration for the formatter would be: php 'formatter' => [ 'locale' => 'fa_IR@calendar=persian', 'calendar' => \IntlDateFormatter::TRADITIONAL, ], Available calendar names can be found in the ICU manual. Since PHP 5.5 you may also use an instance of the [[\IntlCalendar]] class. Check the PHP manual for more details. If the PHP intl extension is not available, setting this property will have no effect.
$currencyCode the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]]. If not set, the currency code corresponding to [[locale]] will be used. Note that in this case the [[locale]] has to be specified with a country code, e.g. en-US otherwise it is not possible to determine the default currency.
$dateFormat the default format string to be used to format a [[asDate()|date]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy' // date in ICU format 'php:m/d/Y' // the same date in PHP format
$datetimeFormat the default format string to be used to format a [[asDatetime()|date and time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy HH:mm:ss' // date and time in ICU format 'php:m/d/Y H:i:s' // the same date and time in PHP format
$decimalSeparator the character displayed as the decimal point when formatting a number. If not set, the decimal separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is '.'.
$defaultTimeZone the time zone that is assumed for input values if they do not include a time zone explicitly. The value must be a valid time zone identifier, e.g. UTC, Europe/Berlin or America/Chicago. Please refer to the php manual for available time zones. It defaults to UTC so you only have to adjust this value if you store datetime values in another time zone in your database.
$locale the locale ID that is used to localize the date and number formatting. For number and date formatting this is only effective when the PHP intl extension is installed. If not set, [[\yii\base\Application::language]] will be used.
$nullDisplay the text to be displayed when formatting a null value. Defaults to '(not set)', where (not set) will be translated according to [[locale]].
$numberFormatterOptions a list of name value pairs that are passed to the intl Numberformatter::setAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following: php [ NumberFormatter::MIN_FRACTION_DIGITS => 0, NumberFormatter::MAX_FRACTION_DIGITS => 2, ]
$numberFormatterSymbols a list of name value pairs that are passed to the intl Numberformatter::setSymbol() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to choose a custom currency symbol, e.g. U+20BD instead of руб. for Russian Ruble: php [ NumberFormatter::CURRENCY_SYMBOL => '₽', ]
$numberFormatterTextOptions a list of name value pairs that are passed to the intl Numberformatter::setTextAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to change the minus sign for negative numbers you can configure this property like the following: php [ NumberFormatter::NEGATIVE_PREFIX => 'MINUS', ]
$sizeFormatBase the base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [[asSize]] and [[asShortSize]]. Defaults to 1024.
$thousandSeparator the character displayed as the thousands separator (also called grouping separator) character when formatting a number. If not set, the thousand separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is ','.
$timeFormat the default format string to be used to format a [[asTime()|time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'HH:mm:ss' // time in ICU format 'php:H:i:s' // the same time in PHP format
$timeZone the time zone to use for formatting time and date values. This can be any value that may be passed to date_default_timezone_set() e.g. UTC, Europe/Berlin or America/Chicago. Refer to the php manual for available time zones. If this property is not set, [[\yii\base\Application::timeZone]] will be used. Note that the default time zone for input data is assumed to be UTC by default if no time zone is included in the input date value. If you store your data in a different time zone in the database, you have to adjust [[defaultTimeZone]] accordingly.

Public Methods

Method Description
asBoolean ( mixed $value ) : string Formats the value as a boolean.
asCurrency ( mixed $value, string $currency = null, array $options = [], array $textOptions = [] ) : string Formats the value as a currency number.
asDate ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a date.
asDatetime ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a datetime.
asDecimal ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a decimal number.
asDuration ( DateInterva\DateInterval | string | integer $value, string $implodeString = ', ', string $negativeSign = '-' ) : string Represents the value as duration in human readable format.
asEmail ( string $value, array $options = [] ) : string Formats the value as a mailto link.
asHtml ( string $value, array | null $config = null ) : string Formats the value as HTML text.
asImage ( mixed $value, array $options = [] ) : string Formats the value as an image tag.
asInteger ( mixed $value, array $options = [], array $textOptions = [] ) : string Formats the value as an integer number by removing any decimal digits without rounding.
asNtext ( string $value ) : string Formats the value as an HTML-encoded plain text with newlines converted into breaks.
asOrdinal ( mixed $value ) : string Formats the value as a ordinal value of a number.
asParagraphs ( string $value ) : string Formats the value as HTML-encoded text paragraphs.
asPercent ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a percent number with "%" sign.
asRaw ( mixed $value ) : string Formats the value as is without any formatting.
asRelativeTime ( integer | string | DateTim\DateTime | DateInterva\DateInterval $value, integer | string | DateTim\DateTime $referenceTime = null ) : string Formats the value as the time interval between a date and now in human readable form.
asScientific ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a scientific number.
asShortSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value in bytes as a size in human readable form for example 12 KB.
asSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value in bytes as a size in human readable form, for example 12 kilobytes.
asSpellout ( mixed $value ) : string Formats the value as a number spellout.
asText ( string $value ) : string Formats the value as an HTML-encoded plain text.
asTime ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a time.
asTimestamp ( integer | string | DateTim\DateTime $value ) : string Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).
asUrl ( mixed $value, array $options = [] ) : string Formats the value as a hyperlink.
format ( mixed $value, string | array $format ) : string Formats the value based on the given format type.
init ( )

Protected Methods

Method Description
createNumberFormatter ( integer $style, integer $decimals = null, array $options = [], array $textOptions = [] ) : NumberFormatter Creates a number formatter based on the given type and format.
normalizeDatetimeValue ( integer | string | DateTim\DateTime $value, boolean $checkTimeInfo = false ) : DateTim\DateTime | array Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods.
normalizeNumericValue ( mixed $value ) : float | integer Normalizes a numeric input value

Private Methods

Method Description
formatDateTimeValue ( integer | string | DateTim\DateTime $value, string $format, string $type ) : string
formatSizeNumber ( string | integer | float $value, integer $decimals, array $options, array $textOptions ) : array Given the value in bytes formats number part of the human readable form.

Method Details

asBoolean() public method

Formats the value as a boolean.
See also: booleanFormat
public asBoolean ( mixed $value ) : string
$value mixed the value to be formatted.
return string the formatted result.

asCurrency() public method

This function does not require the PHP intl extension to be installed to work, but it is highly recommended to install it to get good formatting results.
public asCurrency ( mixed $value, string $currency = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$currency string the 3-letter ISO 4217 currency code indicating the currency to use. If null, [[currencyCode]] will be used.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asDate() public method

Formats the value as a date.
See also: dateFormat
public asDate ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[dateFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
return string the formatted result.

asDatetime() public method

Formats the value as a datetime.
See also: datetimeFormat
public asDatetime ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[dateFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
return string the formatted result.

asDecimal() public method

Property [[decimalSeparator]] will be used to represent the decimal point. The value is rounded automatically to the defined decimal digits.
See also: decimalSeparator
See also: thousandSeparator
public asDecimal ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$decimals integer the number of digits after the decimal point. If not given the number of digits is determined from the [[locale]] and if the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available defaults to `2`.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asDuration() public method

Represents the value as duration in human readable format.
Since: 2.0.7
public asDuration ( DateInterva\DateInterval | string | integer $value, string $implodeString = ', ', string $negativeSign = '-' ) : string
$value DateInterva\DateInterval | string | integer the value to be formatted. Acceptable formats: - [DateInterval object](http://php.net/manual/ru/class.dateinterval.php) - integer - number of seconds. For example: value `131` represents `2 minutes, 11 seconds` - ISO8601 duration format. For example, all of these values represent `1 day, 2 hours, 30 minutes` duration: `2015-01-01T13:00:00Z/2015-01-02T13:30:00Z` - between two datetime values `2015-01-01T13:00:00Z/P1D2H30M` - time interval after datetime value `P1D2H30M/2015-01-02T13:30:00Z` - time interval before datetime value `P1D2H30M` - simply a date interval `P-1D2H30M` - a negative date interval (`-1 day, 2 hours, 30 minutes`)
$implodeString string will be used to concatenate duration parts. Defaults to `, `.
$negativeSign string will be prefixed to the formatted duration, when it is negative. Defaults to `-`.
return string the formatted duration.

asEmail() public method

Formats the value as a mailto link.
public asEmail ( string $value, array $options = [] ) : string
$value string the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::mailto()]].
return string the formatted result.

asHtml() public method

The value will be purified using [[HtmlPurifier]] to avoid XSS attacks. Use Formatter::asRaw if you do not want any purification of the value.
public asHtml ( string $value, array | null $config = null ) : string
$value string the value to be formatted.
$config array | null the configuration for the HTMLPurifier class.
return string the formatted result.

asImage() public method

Formats the value as an image tag.
public asImage ( mixed $value, array $options = [] ) : string
$value mixed the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::img()]].
return string the formatted result.

asInteger() public method

Formats the value as an integer number by removing any decimal digits without rounding.
public asInteger ( mixed $value, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asNtext() public method

Formats the value as an HTML-encoded plain text with newlines converted into breaks.
public asNtext ( string $value ) : string
$value string the value to be formatted.
return string the formatted result.

asOrdinal() public method

This function requires the PHP intl extension to be installed.
public asOrdinal ( mixed $value ) : string
$value mixed the value to be formatted
return string the formatted result.

asParagraphs() public method

Each text paragraph is enclosed within a

tag. One or multiple consecutive empty lines divide two paragraphs.

public asParagraphs ( string $value ) : string
$value string the value to be formatted.
return string the formatted result.

asPercent() public method

Formats the value as a percent number with "%" sign.
public asPercent ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted. It must be a factor e.g. `0.75` will result in `75%`.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asRaw() public method

This method simply returns back the parameter without any format. The only exception is a null value which will be formatted using [[nullDisplay]].
public asRaw ( mixed $value ) : string
$value mixed the value to be formatted.
return string the formatted result.

asRelativeTime() public method

This method can be used in three different ways: 1. Using a timestamp that is relative to now. 2. Using a timestamp that is relative to the $referenceTime. 3. Using a DateInterval object.
public asRelativeTime ( integer | string | DateTim\DateTime | DateInterva\DateInterval $value, integer | string | DateTim\DateTime $referenceTime = null ) : string
$value integer | string | DateTim\DateTime | DateInterva\DateInterval the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object - a PHP DateInterval object (a positive time interval will refer to the past, a negative one to the future)
$referenceTime integer | string | DateTim\DateTime if specified the value is used as a reference time instead of `now` when `$value` is not a `DateInterval` object.
return string the formatted result.

asScientific() public method

Formats the value as a scientific number.
public asScientific ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asShortSize() public method

This is the short form of [[asSize]]. If [[sizeFormatBase]] is 1024, binary prefixes (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
See also: sizeFormatBase
See also: asSize
public asShortSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value string | integer | float value in bytes to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asSize() public method

If [[sizeFormatBase]] is 1024, binary prefixes (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
See also: sizeFormatBase
See also: asShortSize
public asSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value string | integer | float value in bytes to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.

asSpellout() public method

This function requires the PHP intl extension to be installed.
public asSpellout ( mixed $value ) : string
$value mixed the value to be formatted
return string the formatted result.

asText() public method

Formats the value as an HTML-encoded plain text.
public asText ( string $value ) : string
$value string the value to be formatted.
return string the formatted result.

asTime() public method

Formats the value as a time.
See also: timeFormat
public asTime ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[timeFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
return string the formatted result.

asTimestamp() public method

Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).
public asTimestamp ( integer | string | DateTim\DateTime $value ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
return string the formatted result.

asUrl() public method

Formats the value as a hyperlink.
public asUrl ( mixed $value, array $options = [] ) : string
$value mixed the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::a()]].
return string the formatted result.

createNumberFormatter() protected method

You may override this method to create a number formatter based on patterns.
protected createNumberFormatter ( integer $style, integer $decimals = null, array $options = [], array $textOptions = [] ) : NumberFormatter
$style integer the type of the number formatter. Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, ::SPELLOUT, ::ORDINAL ::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return NumberFormatter the created formatter instance

format() public method

This method will call one of the "as" methods available in this class to do the formatting. For type "xyz", the method "asXyz" will be used. For example, if the format is "html", then Formatter::asHtml will be used. Format names are case insensitive.
public format ( mixed $value, string | array $format ) : string
$value mixed the value to be formatted.
$format string | array the format of the value, e.g., "html", "text". To specify additional parameters of the formatting method, you may use an array. The first element of the array specifies the format name, while the rest of the elements will be used as the parameters to the formatting method. For example, a format of `['date', 'Y-m-d']` will cause the invocation of `asDate($value, 'Y-m-d')`.
return string the formatting result.

init() public method

public init ( )

normalizeDatetimeValue() protected method

Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods.
protected normalizeDatetimeValue ( integer | string | DateTim\DateTime $value, boolean $checkTimeInfo = false ) : DateTim\DateTime | array
$value integer | string | DateTim\DateTime the datetime value to be normalized. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$checkTimeInfo boolean whether to also check if the date/time value has some time information attached. Defaults to `false`. If `true`, the method will then return an array with the first element being the normalized timestamp and the second a boolean indicating whether the timestamp has time information or it is just a date value. This parameter is available since version 2.0.1.
return DateTim\DateTime | array the normalized datetime value. Since version 2.0.1 this may also return an array if `$checkTimeInfo` is true. The first element of the array is the normalized timestamp and the second is a boolean indicating whether the timestamp has time information or it is just a date value.

normalizeNumericValue() protected method

- everything empty will result in 0 - a numeric string will be casted to float - everything else will be returned if it is numeric, otherwise an exception is thrown.
protected normalizeNumericValue ( mixed $value ) : float | integer
$value mixed the input value
return float | integer the normalized number value

Property Details

$booleanFormat public_oe property

the text to be displayed when formatting a boolean value. The first element corresponds to the text displayed for false, the second element for true. Defaults to ['No', 'Yes'], where Yes and No will be translated according to [[locale]].
public $booleanFormat

$calendar public_oe property

the calendar to be used for date formatting. The value of this property will be directly passed to the constructor of the IntlDateFormatter class. Defaults to null, which means the Gregorian calendar will be used. You may also explicitly pass the constant \IntlDateFormatter::GREGORIAN for Gregorian calendar. To use an alternative calendar like for example the Jalali calendar, set this property to \IntlDateFormatter::TRADITIONAL. The calendar must then be specified in the [[locale]], for example for the persian calendar the configuration for the formatter would be: php 'formatter' => [ 'locale' => 'fa_IR@calendar=persian', 'calendar' => \IntlDateFormatter::TRADITIONAL, ], Available calendar names can be found in the ICU manual. Since PHP 5.5 you may also use an instance of the [[\IntlCalendar]] class. Check the PHP manual for more details. If the PHP intl extension is not available, setting this property will have no effect.
See also: http://php.net/manual/en/intldateformatter.create.php
See also: http://php.net/manual/en/class.intldateformatter.php#intl.intldateformatter-constants.calendartypes
See also: http://php.net/manual/en/class.intlcalendar.php
Since: 2.0.7
public $calendar

$currencyCode public_oe property

the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]]. If not set, the currency code corresponding to [[locale]] will be used. Note that in this case the [[locale]] has to be specified with a country code, e.g. en-US otherwise it is not possible to determine the default currency.
public $currencyCode

$dateFormat public_oe property

the default format string to be used to format a [[asDate()|date]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy' // date in ICU format 'php:m/d/Y' // the same date in PHP format
public $dateFormat

$datetimeFormat public_oe property

the default format string to be used to format a [[asDatetime()|date and time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy HH:mm:ss' // date and time in ICU format 'php:m/d/Y H:i:s' // the same date and time in PHP format
public $datetimeFormat

$decimalSeparator public_oe property

the character displayed as the decimal point when formatting a number. If not set, the decimal separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is '.'.
public $decimalSeparator

$defaultTimeZone public_oe property

the time zone that is assumed for input values if they do not include a time zone explicitly. The value must be a valid time zone identifier, e.g. UTC, Europe/Berlin or America/Chicago. Please refer to the php manual for available time zones. It defaults to UTC so you only have to adjust this value if you store datetime values in another time zone in your database.
Since: 2.0.1
public $defaultTimeZone

$locale public_oe property

the locale ID that is used to localize the date and number formatting. For number and date formatting this is only effective when the PHP intl extension is installed. If not set, [[\yii\base\Application::language]] will be used.
public $locale

$nullDisplay public_oe property

the text to be displayed when formatting a null value. Defaults to '(not set)', where (not set) will be translated according to [[locale]].
public $nullDisplay

$numberFormatterOptions public_oe property

a list of name value pairs that are passed to the intl Numberformatter::setAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following: php [ NumberFormatter::MIN_FRACTION_DIGITS => 0, NumberFormatter::MAX_FRACTION_DIGITS => 2, ]
public $numberFormatterOptions

$numberFormatterSymbols public_oe property

a list of name value pairs that are passed to the intl Numberformatter::setSymbol() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to choose a custom currency symbol, e.g. U+20BD instead of руб. for Russian Ruble: php [ NumberFormatter::CURRENCY_SYMBOL => '₽', ]
Since: 2.0.4
public $numberFormatterSymbols

$numberFormatterTextOptions public_oe property

a list of name value pairs that are passed to the intl Numberformatter::setTextAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to change the minus sign for negative numbers you can configure this property like the following: php [ NumberFormatter::NEGATIVE_PREFIX => 'MINUS', ]
public $numberFormatterTextOptions

$sizeFormatBase public_oe property

the base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [[asSize]] and [[asShortSize]]. Defaults to 1024.
public $sizeFormatBase

$thousandSeparator public_oe property

the character displayed as the thousands separator (also called grouping separator) character when formatting a number. If not set, the thousand separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is ','.
public $thousandSeparator

$timeFormat public_oe property

the default format string to be used to format a [[asTime()|time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'HH:mm:ss' // time in ICU format 'php:H:i:s' // the same time in PHP format
public $timeFormat

$timeZone public_oe property

the time zone to use for formatting time and date values. This can be any value that may be passed to date_default_timezone_set() e.g. UTC, Europe/Berlin or America/Chicago. Refer to the php manual for available time zones. If this property is not set, [[\yii\base\Application::timeZone]] will be used. Note that the default time zone for input data is assumed to be UTC by default if no time zone is included in the input date value. If you store your data in a different time zone in the database, you have to adjust [[defaultTimeZone]] accordingly.
public $timeZone