M
M
Mark2018-06-20 19:49:50
Yii
Mark, 2018-06-20 19:49:50

How to set date format for all Yii2 GridView?

Hello. You need to set the date format for all GridViews to date- Y-m-d, and to dateTime- Y-m-d | H.i.s.
I tried to set the settings for the formatter in the settings of the application components:

'formatter' => [
            'dateFormat' => 'php:Y-m-d',
            'datetimeFormat' => 'php:Y-m-d | H.i.s',
        ],

Didn't help, output to GridView: Jun 20, 2018 4:21:00 PM.
The date in the GridView: is not hardcoded ( 'date:dateTime')
inb4: it is reluctant to register through the attribute value directly, because there are many GridViews, and some kind of crutch. I would like to ask globally.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-06-20
@MarkLb

Good evening.
Your setup works fine.

'formatter' => [
            'class' => 'yii\i18n\Formatter',
            'dateFormat' => 'dd MMMM yyyy',
            'defaultTimeZone' => 'Europe/Kiev',
            'datetimeFormat' => 'php: Y-m-d | H.i.s',
            'locale' => 'ru'
        ]

With this configuration, the date value displays as you need.
In the gridview you specify the attribute
and you get it
Perhaps you need to install the php-intl package, well, specify the class in the formatter setting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question