cakephp 3 displaying date without time

…衆ロ難τιáo~ 提交于 2019-12-06 21:20:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!