Issue
I am working in cakephp 3 and I want to print my time object in Y-m-d format.
This is my object
'expiry' => object(Cake\I18n\Time) {
'time' => '2015-07-31T00:00:00+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
Can anyone help me with this?
Solution
In Cakephp 3.* you use the Time::i18nFormat() method. It worked for me
$customformat = $date->i18nFormat('YYY-MM-dd');
Edit:
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'
Edit 2:
Also look at the time helper class
You can reference it in views like so:
$this->Time->format($format);
Answered By - Peter Chaula
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.