I have the following snippet of code:
setlocale(LC_ALL, "de");
print(strftime("%A %e %B %Y", time()));
and it's printing
Tuesday 4 May 2010
instead of
Dienstag 4. Mai 2010
Any ideas why? How to fix?
I have the following snippet of code:
setlocale(LC_ALL, "de");
print(strftime("%A %e %B %Y", time()));
and it's printing
Tuesday 4 May 2010
instead of
Dienstag 4. Mai 2010
Any ideas why? How to fix?
maybe you don't have the locale installed so if you are on ubuntu you can check the list with "locale -a" without the cuotes, and check the available languajes in the file /usr/share/i18n/SUPPORTED and them generated the locale required with "locale-gen de_DE"
hope this work for you.
I am using Ubuntu on Raspberry Pi, had the same issue trying to use Portuguese local for date:
Then checked with command local -a, pt_PT was not on the list, so I added it sudo /usr/share/locales/install-language-pack pt_PT and run local -a again: there it was pt_PT.utf8. After this, result still the same: output expected for pt_PT still in English. Here is the slight difference that made things work to me:
So, I had to turn pt_PT into pt_PT.utf8
Do you have the
de
locale available; what doessetlocale
return for you? See: return values for setlocale().Also, check the list of available locales (e.g.
locale -a
or whatever is suitable for your OS) to see ifde
is among them. Likely alternatives includede_DE
orde_DE.utf8
to name a few.In Debian, to generate a new locale, run this command:
and pick the ones you want.
For me the following did the trick:
In combination with:
That is how I got the current date in German format. Hope that can help.
Please be aware that you will probably need to restart httpd and php-fpm deamons after generating new locales in Linux.
Without restart php (7.2) couldn't find them, even when listed in locale -a.
Hope it will save someone some time :)