Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polish months in date formatting

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?

like image 670
user1583209 Avatar asked Dec 16 '22 07:12

user1583209


1 Answers

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.

like image 114
akky Avatar answered Dec 21 '22 23:12

akky