title: Format the datetime value in Yii 2
body: <p>The datetime value saved in database is "<code>2014-06-30 02:52:51.210201</code>".</p>
  
  <p>This is also the value displayed by Yii.</p>
  
  <p>What is the best approach to display it as "<code>30-06-2014 02:52:51</code>" everywhere?</p>
  
  <p>Found this in <a href="http://www.yiiframework.com/wiki/684/save-and-display-date-time-fields-in-different-formats-in-yii2/" rel="nofollow noreferrer">Yii's wiki</a> but don't know how to use it:</p>
  
  <blockquote>
    <p>You can configure yii\i18n\formatter to control your global date
    formats for display for your locale. You can set something like this
    in your config file that you can access across</p>
  
  <pre><code>'formatter' =&gt; [
   'class' =&gt; 'yii\i18n\Formatter',
   'dateFormat' =&gt; 'd-M-Y',
   'datetimeFormat' =&gt; 'd-M-Y H:i:s',
   'timeFormat' =&gt; 'H:i:s', ]`
  </code></pre>
    
    <p>Then you can display your date times anywhere using the formatter
    specified formats:</p>
    
    <p><code>echo \Yii::t('app', 'Today is {0, date}', $yourTimeStampAttr);</code></p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I create a custom attribute for the model to retrieve the time</p>
  
  <pre><code>public function getFormattedCreateTime()
  {
      return DateTime::createFromFormat('Y-m-d H:i:s.u', $this-&gt;create_time)-&gt;format('d-m-Y H:i:s');
  }
  </code></pre>
  
  <p>another problem though, how do I use this attribute for search in Yii 2's GridView ? thanks</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>can add the custom attribute for search by inherits the search function</p>