DatetimeFormatter
class DatetimeFormatter implements FormatterInterface (View source)
Formatter for date and time.
This is not full implementation of features from CLDR. These are missing:
- support for other calendars than Gregorian
- rules for displaying timezone names are simplified
- some less frequently used format characters are not supported
Properties
protected DatesReader | $datesReader |
Methods
Returns dateTime formatted by custom format, string provided in parameter.
Formats date with format string for date defined in CLDR for particular locale.
Formats time with format string for time defined in CLDR for particular locale.
Formats dateTime with format string for date and time defined in CLDR for particular locale.
Formats provided dateTime object.
Formats date or time element according to the subpattern provided.
Pads given string to the specified length with zeros.
Details
void
injectDatesReader(DatesReader $datesReader)
No description
string
format(mixed $value, Locale $locale, array $styleProperties = [])
Formats provided value using optional style properties
string
formatDateTimeWithCustomPattern(DateTimeInterface $dateTime, string $format, Locale $locale)
Returns dateTime formatted by custom format, string provided in parameter.
Format must obey syntax defined in CLDR specification, excluding unimplemented features (see documentation for DatesReader class).
Format is remembered in this classes cache and won't be parsed again for some time.
string
formatDate(DateTimeInterface $date, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT)
Formats date with format string for date defined in CLDR for particular locale.
string
formatTime(DateTimeInterface $time, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT)
Formats time with format string for time defined in CLDR for particular locale.
string
formatDateTime(DateTimeInterface $dateTime, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT)
Formats dateTime with format string for date and time defined in CLDR for particular locale.
First date and time are formatted separately, and then dateTime format from CLDR is used to place date and time in correct order.
protected string
doFormattingWithParsedFormat(DateTimeInterface $dateTime, array $parsedFormat, array $localizedLiterals)
Formats provided dateTime object.
Format rules defined in $parsedFormat array are used. Localizable literals are replaced with elements from $localizedLiterals array.
protected string
doFormattingForSubpattern(DateTimeInterface $dateTime, string $subformat, array $localizedLiterals)
Formats date or time element according to the subpattern provided.
Returns a string with formatted one "part" of DateTime object (seconds, day, month etc).
Not all pattern symbols defined in CLDR are supported; some of the rules are simplified. Please see the documentation for DatesReader for details.
Cases in the code are ordered in such way that probably mostly used are on the top (but they are also grouped by similarity).
protected string
padString(string $string, int $formatLength)
Pads given string to the specified length with zeros.