doupu3211 2014-06-16 04:49 采纳率: 100%
浏览 47
已采纳

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>';
}
  • 写回答

2条回答 默认 最新

  • dongwei9771 2014-06-16 05:12
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理