ToX 82
ToX 82

Reputation: 1074

Show dates in a custom format

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?

Upvotes: 1

Views: 571

Answers (1)

Holt
Holt

Reputation: 37686

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

Upvotes: 1

Related Questions