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?
The param dateFormat
only has effect for asDate()
. For asDatetime()
set datetimeFormat
.