0

我正在使用 CakePHP 3.2。

我想将timestamp数据库中的日期与isThisMonth()CakePHP 的功能进行比较。

我正在列出created日期在 内的产品1 month。它将显示NEW带有产品的徽章。

这就是我所做的

<?php $date = new DateTime($product->created);
      $date = $date->format('Y-m-d');
      if ($date->isThisMonth()): ?>   // error is pointing this line
         <span class="new-product"> NEW</span>
<?php endif; ?>

$product是一个错误项,created是数据库中的时间戳列。

但这给出了错误

Call to a member function isThisMonth() on string
4

1 回答 1

1

尝试在下面添加$date = $date->format('Y-m-d');

$time = new Time($date);

$date->isThisMonth()):然后交换$time->isThisMonth()):

http://book.cakephp.org/3.0/en/core-libraries/time.html#comparing-with-the-present

包括use Cake\I18n\Time;view.ctp.

于 2016-07-13T17:41:47.147 回答