Detailed example of Yii 2.0 formatting time in Grid

怪我咯
Release: 2023-03-10 14:16:01
Original
1196 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 it is displayed The time is in English, it doesn’t matter, we can configure

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!