以Y-m-d格式转换cakephp 3的时间对象 [英] Convert time object of cakephp 3 in Y-m-d format
本文介绍了以Y-m-d格式转换cakephp 3的时间对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Cakecake 3中工作,我想以Ymd格式打印时间对象。
I am working in cakephp 3 and I want to print my time object in Y-m-d format.
这是我的对象
'expiry' => object(Cake\I18n\Time) {
'time' => '2015-07-31T00:00:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
有人可以帮助我吗?
推荐答案
在Cakephp 3. *中,您使用 Time :: i18nFormat()
方法。
In Cakephp 3.* you use the Time::i18nFormat()
method. It worked for me
$customformat = $date->i18nFormat('YYY-MM-dd');
编辑:
我通过 3.3 文档,发现了一个很好的例子。您可以使用常量来格式化常见用例的日期,例如 Time :: UNIX_TIMESTAMP_FORMAT
, \IntlDateFormatter :: FULL
I looked through the 3.3 docs and found this good example. There are constants you can use to format dates for common use cases like 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'
编辑2:
还要查看时间助手class
您可以在如下视图中引用它:
You can reference it in views like so:
$ this-> Time-> format($ format);
这篇关于以Y-m-d格式转换cakephp 3的时间对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文