在我的 AppController beforeFilter 中,我将用户数据保存到变量中以便在我的视图中使用。我需要获取作为日期时间的 last_login 字段,然后使用 dateformat 函数显示我想要的日期,但是 cakephp 将此变量输出为字符串,有没有办法将表格的格式作为输入?(约会时间)。
// Set user variables for each page load
$id = $this->Auth->user('id');
// Set $id
$user_data = $this->User->findById($id);
// Set User Last Login
$user_lastlogin = $user_data['User']['last_login'];
$this->set('lastLogin', $user_lastlogin);
看法
<?php echo date_format($lastLogin, 'F jS \at h:i:s A'); ?>
错误
Warning (2): date_format() expects parameter 1 to be DateTime, string given