以Ymd格式转换cakephp 3的时间对象

Sai*_*ain 2 cakephp cakephp-3.0

我在cakephp 3工作,我想以Ymd格式打印我的时间对象.

这是我的目标

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

谁能帮我这个?

pet*_*ula 10

这个问题已经很老了,但这也让我很头疼.在Cakephp 3.*中,您只需使用该Time::i18nFormat()方法.它对我有用

  $customformat = $date->i18nFormat('YYY-MM-dd');
Run Code Online (Sandbox Code Playgroud)

编辑:

我查看了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'
Run Code Online (Sandbox Code Playgroud)

CakePHP文档

编辑2:

另请看时间助手类

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

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