This article mainly shares with you the relevant information about formatting time in Grid in Yii 2.0. The article provides detailed sample code for your reference and study. It has certain reference value for everyone. Friends who need it can follow it. Let’s take a look.
This article mainly introduces to you the relevant content about Yii 2.0 formatting time in Grid, and shares it for your reference and study. Let’s take a look at the detailed introduction:
Go directly to the code
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'id', 'username', 'email:email', 'created_at:date', // 这两个需要显示为 2016.04.10 'updated_at:date', // 使用 :date 来格式化时间 ['class' => 'yii\grid\ActionColumn'], ], ]); ?>
When you use :date
to format the time, you will find that it is displayed The time is in English, it doesn’t matter, we can configure
In main.php, add a few lines to components
'components' => [ 'formatter' => [ 'dateFormat' => 'YYY.MM.dd', 'decimalSeparator' => ',', 'thousandSeparator' => ' ', 'currencyCode' => 'EUR', ],
The above is the detailed content of Detailed example of Yii 2.0 formatting time in Grid. For more information, please follow other related articles on the PHP Chinese website!