"- the server does not accept Portuguese-Brazilian, even in the php manual that accepts"
Done some research on the setlocale
, I can conclude that he has no direct connection to timezone
or the version of your PHP server. But it is directly dependent on the operating system on which your PHP server is running!
As an example, my development environment, running Windows 10 and PHP through Uniserver Zero XIII, brought the following results:
// locale string atual:
echo setlocale(LC_TIME, 0); // C
echo setlocale(LC_ALL, 0); // LC_COLLATE=C;LC_CTYPE=Portuguese_Brazil.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
setlocale(LC_ALL, 'portuguese-brazilian');
echo strftime('%A, %d de %B de %Y'); // domingo, 17 de mar�o de 2019
setlocale(LC_ALL, 'portuguese-brazilian.utf8');
echo strftime('%A, %d de %B de %Y'); // domingo, 17 de março de 2019
setlocale(LC_ALL, 'pt_BR');
echo strftime('%A, %d de %B de %Y'); // domingo, 17 de março de 2019
setlocale(LC_ALL, 'pt_BR.utf8');
echo strftime('%A, %d de %B de %Y'); // domingo, 17 de março de 2019
setlocale(LC_ALL, 'pt_BR.iso-8859-1');
echo strftime('%A, %d de %B de %Y'); // Sunday, 17 de March de 2019
setlocale(LC_ALL, 'portuguese');
echo strftime('%A, %d de %B de %Y'); // domingo, 17 de mar�o de 2019
The PHP documentation itself recommends that Windows users search for local string (string locale) in the Microsoft MSDN website:
Tip Windows users found useful information about locale strings on Microsoft’s MSDN site. Supported language strings can be found » here the supported country/region strings » here. Windows systems support three-letter country/region codes specified by ISO 3166-Alpha-3, which can be found on Unicode website. - PHP: setlocale
But I found it more convenient through Table of Moodle site locations. That’s good: there’s no way to add new locations in Windows. Already on Linux it is possible to install new locations and some distributions already have all by default. Moodle, inclusive, explains this.
Another issue is that you can define several locale strings at once and PHP takes care of defining "what to find first".
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese", ...);
Note: this does not mean that it will define the best!
Another recommendation is, if feasible, to always return to the default after displaying your date with the language in question. This will prevent possible incompatibilities related to several other PHP functions. See reports in User Contributed Notes in setlocale documentation.
Overall, if you have root access to your server, it won’t be hard to find a valid option. If not, you will have to surrender to the support of the company that hosts your site - which does not always meet expectations, where everything they don’t want to do is turned into "violates security policy".
the date is displayed only with numbers? ex: 14/03/2019
– Tales Peres
do not display texts in English, as ex(Thursday)
– Douglas
If I’m not mistaken,
date
always returns the texts in English. The Timezone only serves to know the current date and time to be considered (since it varies according to the time zone), and the language has nothing to do with Timezone. If you want texts in another language, usestrftime
along withsetlocale
– hkotsubo
I am using this setlocale setlocale {(LC_TIME, "English-Brazilian");} yet strtime ignores
– Douglas
I don’t know if PHP recognizes "Portuguese-Brazilian", it has to be "pt_BR". Also see if the locale is installed on the server: https://stackoverflow.com/q/10909911
– hkotsubo
Possible duplicate of How to make the date() function format a date in English?
– LipESprY
I will see if it is installed, but "Portuguese-Brazilian" works, because at least on the localhost it recognizes, I only have this problem in the hosting server
– Douglas
@Lipespry is not duplicated, I looked but this is not this problem
– Douglas
Solved, the server does not accept Portuguese-Brazilian, even in the php manual that accepts
– Douglas
In fact
setlocale
returnsfalse
when the locale is not recognized (and if I’m not mistaken, it shows no error message). And then the locale is not changed and it uses what was already configured before (and the localhost was probably Portuguese, and the English server). Check the return ofsetlocale
just to be sure... and in the manual I only saw that you acceptPortuguese_Brazilian
, but only in Windows, in other systems is pt_BR same– hkotsubo