The beautiful Polish language uses different grammar for the name of the months when saying things like "March 2013" (without day) vs. "March 17 2013" (with day).
Using PHP's strftime()
with %B
gives the correct name of the month for the without-day-case. How can I properly write the date in the with-day-case? Do I have to code something myself or is there already some support for such cases?
There is IntlDateFormatter, an international version of DateFormatter since PHP5.3 if you turn on intl extension.
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
exit ('IntlDateFormatter is available on PHP 5.3.0 or later.');
}
if (!class_exists('IntlDateFormatter')) {
exit ('You need to install php_intl extension.');
}
$polishDateFormatter = new IntlDateFormatter(
'pl_PL',
IntlDateFormatter::LONG,
IntlDateFormatter::NONE
);
$now = new DateTime("2013-08-06");
echo $polishDateFormatter->format($now), "\n";
This code returns me,
6 sierpnia 2013
which I hope correct. (I know no Polish ;-)
You may also check IntlDateFormatter::SHORT, MEDIUM and FULL to get another notations at the second parameter of the constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With