IntlDatePatternGenerator
Generates localized date and/or time format pattern strings suitable for use in IntlDateFormatter
Transforms unordered skeleton formats like "MMddyyyy" to use the correct ordering and separators for the locale (for example, one locale might use "dd-MM-yyyy" when another uses "yyyy/MM/dd").
See Unicode UTS #35 appendix F (Date Format Patterns) for valid input format patterns: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
Example usage: $locale = 'en_US'; $generator = IntlDatePatternGenerator::createInstance($locale); $pattern = $generator->getBestPattern('MMddyyyy'); $formatter = IntlDateFormatter::create($locale, null, null); $formatter->setPattern($pattern); $date = $formatter->format(new DateTime());
Constants:
Pattern fields: IntlDatePatternGenerator::ERA_PATTERN_FIELD IntlDatePatternGenerator::YEAR_PATTERN_FIELD IntlDatePatternGenerator::QUARTER_PATTERN_FIELD IntlDatePatternGenerator::MONTH_PATTERN_FIELD IntlDatePatternGenerator::WEEK_OF_YEAR_PATTERN_FIELD IntlDatePatternGenerator::WEEK_OF_MONTH_PATTERN_FIELD IntlDatePatternGenerator::WEEKDAY_PATTERN_FIELD IntlDatePatternGenerator::DAY_OF_YEAR_PATTERN_FIELD IntlDatePatternGenerator::DAY_OF_WEEK_IN_MONTH_PATTERN_FIELD IntlDatePatternGenerator::DAY_PATTERN_FIELD IntlDatePatternGenerator::DAYPERIOD_PATTERN_FIELD IntlDatePatternGenerator::HOUR_PATTERN_FIELD IntlDatePatternGenerator::MINUTE_PATTERN_FIELD IntlDatePatternGenerator::SECOND_PATTERN_FIELD IntlDatePatternGenerator::FRACTIONAL_SECOND_PATTERN_FIELD IntlDatePatternGenerator::ZONE_PATTERN_FIELD
Pattern conflict status: IntlDatePatternGenerator::PATTERN_NO_CONFLICT IntlDatePatternGenerator::PATTERN_BASE_CONFLICT IntlDatePatternGenerator::PATTERN_CONFLICT
Interface Synopsis
class IntlDatePatternGenerator {...}
Public Methods
-
::createEmptyInstance(): IntlDatePatternGenerator
Creates an empty generator, to be constructed with addPattern(...) etc -
::createInstance(string $locale): IntlDatePatternGenerator
Creates a flexible generator according to the data for a given locale -
->addPattern(string $pattern, bool $override): int
Adds a pattern to the generator -
->getBaseSkeleton(string $pattern): string
Utility to return a unique base skeleton from a given pattern -
->getBestPattern(string $skeleton): string
Returns the best pattern matching the input skeleton -
->getDecimal(): string
The decimal value is used in formatting fractions of seconds -
->getErrorCode(): int
Get last error code on the object -
->getErrorMessage(): string
Get last error message on the object -
->getPatternForSkeleton(string $skeleton): string
Get the pattern corresponding to a given skeleton -
->getSkeleton(string $pattern): string
Utility to return a unique skeleton from a given pattern -
->replaceFieldTypes(string $pattern, string $skeleton): string
Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton -
->setAppendItemFormat(int $field, string $value): void
An append item format is a pattern used to append a field if there is no good match -
->setAppendItemName(int $field, string $name): void
Sets the name of a field, eg "era" in English for ERA -
->setDateTimeFormat(string $dateTimeFormat): void
The date time format is a message format pattern used to compose date and time patterns -
->setDecimal(string $decimal): void
The decimal value is used in formatting fractions of seconds