Change the default i18n date formats

i18n
#1

Hi all.
I need to change the default date formats for italian, french and german languages.
Is there any way to set it in bootstrap.php / application.php?
I wish to avoid dozens of “ifs” in my templates.
I’m on Cake 3.7

#2

https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#localizing-dates-and-numbers

#3

I tried but without success

#4

Show what you have tried, and explain what’s not working about it.

#5

I followed the steps described in this chapter

https://book.cakephp.org/3.0/en/core-libraries/time.html#setting-the-default-locale-and-format-string

I added this code to my bootstrap.php, just to test if it will work

Time::setToStringFormat('HH ss yyyy');
FrozenTime::setToStringFormat('HH ss yyyy');
Date::setToStringFormat('HH ss yyyy');
FrozenDate::setToStringFormat('HH ss yyyy');

Unfortunately it didn’t

#6

What does the code you’re using to actually output values look like? You are still not showing nearly enough of what you’re doing for us to be able to really help.

#7

<td class="date"><?= $order->created_on->nice(); ?></td>

created_on is a ‘date’ field, mapped to a FrozenTime object by Cake

#8

If you look again at the link I gave, it seems that the “string format” is used by the i18nFormat function. The nice function uses the default locale, which you’re not setting in the code you’ve shown.