PHP date_format [关闭]

I have an array named $dataArray, i want to show all the array content in my View, but there's some problem when I echo the date. The error is:

date_format() expects parameter 1 to be DateTimeInterface, string given

Here's the code

foreach ($dataArray as $data){                                                          
   echo '<tr align="center">';
   echo '<td>';
   echo CHtml::encode($data->first_name);
   echo ' ';
   echo CHtml::encode($data->last_name);
   echo '</td>';
   echo '<td>';
   $date = ($data->join);
   echo date_format($date,'Y/m/d');
   echo '</td>';
   echo '<td>';
   echo CHtml::encode($data->last_login);
   echo '</td>';
   echo '<td>';
   echo '</tr>';
}

In order to use date_format, you must first use the date_create() method. Take a look at the examples on that page for reference.

$date = date_create($data->join);
echo date_format($date, 'Y/m/d');

OR

You can also the native date() function

$date = date('Y/m/d', strtotime($data->join));
echo $date;

You can use php date() function

<?php  

      echo date("Y/m/d H:i:s",strtotime($date));

 php>