Home  >  Article  >  Backend Development  >  Analyze Yii 2.0's method of time formatting in Grid

Analyze Yii 2.0's method of time formatting in Grid

巴扎黑
巴扎黑Original
2017-08-09 14:55:241326browse

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


 $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 the displayed time is 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 Analyze Yii 2.0's method of time formatting in Grid. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn