1
votes

I'm having a problem with the yii2 date formatter, it doesn't use the locale that I have set. The global language is set to de-DE, it seems to take effect everywhere except for the date formatter. I've tryed to set the formatter locale in the config file like this:

 'formatter' => [
        'dateFormat' => 'dd.MM.yyyy',            
        'decimalSeparator' => ',',
        'thousandSeparator' => ' ',
        'currencyCode' => 'EUR',
        'locale'=>'de_DE'
   ],

and also directly before using the formatter in code:

Yii::$app->formatter->locale = 'de-DE';
echo Yii::$app->formatter->asDatetime('2014-01-01'); 

but it formats the date to Jan 1, 2014 10:04:36 AM. Any ideas?

2
The question is somehow wrong. It is no locale issue occuring with the code, it is caused by a wrong property usage. - Jako

2 Answers

1
votes

The param dateFormat only has effect for asDate(). For asDatetime() set datetimeFormat.

0
votes

possible reason: check and make sure that php-intl extension is installed.

see: https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n#parameter-formatting