Show dates in a custom format

两盒软妹~` 提交于 2019-12-24 11:28:04

问题


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.

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 :)

How can I override the default behavior of the italian locale, to obtain 4 digits years?


回答1:


You should try:

\Cake\I18n\Time::setToStringFormat('dd/MM/YYYY HH:mm:ss');

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 () ;
}


来源:https://stackoverflow.com/questions/31635700/show-dates-in-a-custom-format

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