以Y-m-d格式转换cakephp 3的时间对象

问题描述 投票:2回答:4

我在cakephp 3工作,我想以Y-m-d格式打印我的时间对象。

这是我的目标

'expiry' => object(Cake\I18n\Time) {
        'time' => '2015-07-31T00:00:00+0000',
        'timezone' => 'UTC',
        'fixedNowTime' => false
},

谁能帮我这个?

cakephp cakephp-3.0
4个回答
10
投票

在Cakephp 3. *中,您使用Time::i18nFormat()方法。它对我有用

  $customformat = $date->i18nFormat('YYY-MM-dd');

编辑:

我查看了3.3文档并找到了这个很好的例子。您可以使用常量来设置常见用例的日期格式,例如Time::UNIX_TIMESTAMP_FORMAT\IntlDateFormatter::FULL

$time = new Time('2014-04-20 22:10');
$time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale
$time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format
$time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format
$time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10'
$time->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'

CakePHP documentation

编辑2:

还看看time helper class

您可以在以下视图中引用它:

$this->Time->format($format);


4
投票

$object->created->format('Y-m-d')


0
投票

我做的。我所要做的就是在我的视图中使用Time助手。 $this->Time->format($user->expiry,'Y-M-d')


0
投票

得到dt_updated小于当前日期的结果。

$result = $this->ModelTable->find('all');
$result->where(['DATE(dt_updated) <'=>date('Y-m-d')]);
© www.soinside.com 2019 - 2024. All rights reserved.