I want to remove "day" from the pattern to display the correct INTL date in format "F, Y". How to correctly do it without str_replace-ing "d" character with dots (and other symbols) in the $tempPattern variable?
I can't use $formatter->setPattern(), as the date format is different for each language.
function getLocaleDateFormate($locale) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::NONE);
// replace M with L: stand-alone month in year
$tempPattern = $formatter->getPattern();
$tempPattern = str_replace("M", "L", $tempPattern);
return $tempPattern;
}
echo getLocaleDateFormate("sk"); // d. LLLL y
echo getLocaleDateFormate("hu"); // y. LLLL d.
echo getLocaleDateFormate("de"); // d. LLLL y
echo getLocaleDateFormate("es"); // d 'de' LLLL 'de' y
echo getLocaleDateFormate("pl"); // d LLLL y
echo getLocaleDateFormate("cn"); // y年L月d
The output is not in the correct order (it forces the 'LLLL y' order for each language), so I applied the corrections for specific languages. I am not satisfied fully but I don't have any better solution.