以自定义格式显示日期 [英] Show dates in a custom format
问题描述
我正在使用CakePHP 3.0.10,而且我试图在我的应用程序中使用这个日期格式 dd / mm / yyyy
而不是 yyyy-mm-dd
。
I'm using CakePHP 3.0.10 and I'm trying to use this date format dd/mm/yyyy
everywhere in my application, instead of yyyy-mm-dd
.
从文档中我知道我可以使用 ini_set('intl。 default_locale','it_IT');
设置在我的 bootstrap.php
文件中进行大部分肮脏的工作,但是我仍然获得日期 dd / mm / yy
格式,这对我来说不好。将它设置为 fr_FR
返回正确的格式,但显然我错过了所有的翻译,反正这是错误的:)
I know from the documentation that I can use ini_set('intl.default_locale', 'it_IT');
setting in my bootstrap.php
file to do most of the dirty work, but still I am obtaining dates in dd/mm/yy
format, which is not good for me. Setting it to fr_FR
returns the right format, but obviously I'm missing all the translations and it is just wrong anyway :)
如何覆盖意大利语言区域的默认行为,以获得4位数字?
How can I override the default behavior of the italian locale, to obtain 4 digits years?
推荐答案
您应该尝试:
\Cake\I18n\Time::setToStringFormat('dd/MM/YYYY HH:mm:ss');
请参阅 CakePHP文档,你可以把这一行放在 beforeRender
回调你的
AppController
:
See CakePHP documentation, you could put this line in the beforeRender
callback of your AppController
:
public function beforeRender (\Cake\Event\Event $event) {
\Cake\I18n\Time::setToStringFormat('dd/MM/YYYY HH:mm:ss');
return parent::beforeRender () ;
}
这篇关于以自定义格式显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!