PHP example-Yii 2.0 format time method example in Grid

微波
Release: 2023-03-11 18:34:02
Original
1114 people have browsed it

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([ 
 &#39;dataProvider&#39; => $dataProvider,
 &#39;columns&#39; => [
 [&#39;class&#39; => &#39;yii\grid\SerialColumn&#39;],

 &#39;id&#39;,
 &#39;username&#39;,
 &#39;email:email&#39;,
 &#39;created_at:date&#39;, // 这两个需要显示为 2016.04.10
 &#39;updated_at:date&#39;, // 使用 :date 来格式化时间

 [&#39;class&#39; => &#39;yii\grid\ActionColumn&#39;],
],
]); ?>
Copy after login

When you use :date to format the time, you will find that the displayed time is in English, it doesn’t matter, we can configure it

In main.php, add a few lines to components

&#39;components&#39; => [

  &#39;formatter&#39; => [
   &#39;dateFormat&#39; => &#39;YYY.MM.dd&#39;,
   &#39;decimalSeparator&#39; => &#39;,&#39;,
   &#39;thousandSeparator&#39; => &#39; &#39;,
   &#39;currencyCode&#39; => &#39;EUR&#39;,
  ],
Copy after login

Summary

The above is the detailed content of PHP example-Yii 2.0 format time method example in Grid. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template