问题
CakePHP 3: I have a database field which is a DATE (not DATETIME nor TIMESTAMP)
When I display
echo $contact->date;
It will show something like 2014. 01. 06. 0:00. How to hide hours and minutes?
I tried
print $this->Time->format($contact->date, 'Y-m-d');
but I got 2014-0-6
How to get year-month-day?
rrd
回答1:
Have you tried this?
echo $contact->date->format('Y-m-d');
回答2:
add in App\Controller:
use Cake\I18n\Time;
Time::$defaultLocale = 'es-ES';
Time::setToStringFormat('YYYY-MM-dd');
回答3:
If need all over the project with specific format you can use
boostrap.php
Cake\I18n\FrozenDate::setToStringFormat('yyyy-MM-dd');
回答4:
echo date_format($contact->date, 'Y-m-d'); //php format
回答5:
try
date('Y-m-d',strtotime($contact->date));
来源:https://stackoverflow.com/questions/26561226/cakephp-3-displaying-date-without-time