title: yii2:formatting of date for display
body: <p>I have configured a date field appointment_date as <code>datetime</code> field in mysql db.</p>
  
  <p>In my model Appointment.php rules are set like this:</p>
  
  <pre><code>public function rules()
      {
          return [
              [['appointment_date','weekdays'], 'safe'],
              [['appointment_date'], 'date','format' =&gt; 'd-M-yyyy H:m'],
  </code></pre>
  
  <p>and in web.php under component I have set</p>
  
  <pre><code>'formatter' =&gt; [
          'defaultTimeZone' =&gt; 'UTC',
          'timeZone' =&gt; 'Asia/Kolkata',
  </code></pre>
  
  <p>and in my view I am trying to format the date for display like this:</p>
  
  <pre><code>[
      Yii::$app-&gt;formatter-&gt;asDatetime('appointment_date')
   ],
  </code></pre>
  
  <p>Now I am getting the error - </p>
  
  <pre><code>appointment_date' is not a valid date time value: DateTime::__construct(): Failed to parse time string (appointment_date) at position 0 (a): The timezone could not be found in the database
  Array
  (
  [warning_count] =&gt; 1
  [warnings] =&gt; Array
  (
  [6] =&gt; Double timezone specification
  )
  
  [error_count] =&gt; 3
  [errors] =&gt; Array
  (
  [0] =&gt; The timezone could not be found in the database
  [11] =&gt; Unexpected character
  [12] =&gt; Double timezone specification
  )
  </code></pre>
  
  <p>Whereas the date stored in the database is like : 2015-01-20 11:50:00</p>
  
  <p>If I am not formatting the date and simply keeping the attribute in view as 
  <code>appointment_date</code> then the date is shown as <code>2015-01-20 11:50:00</code></p>
  
  <p>I want to show the date as <code>20-01-2015 11:50:00</code></p>
  
  <p>If I am using the code like this:</p>
  
  <pre><code>[
      'attribute'=&gt;'appointment_date',
       'format'=&gt;['DateTime','php:d-m-Y H:i:s']
              ],
  </code></pre>
  
  <p>I am getting the date formatted correctly.</p>
  
  <p>I want to know What I am doing wrong here in using </p>
  
  <pre><code>Yii::$app-&gt;formatter-&gt;asDatetime('appointment_date')
  </code></pre>
  
  <p>Thanks</p>