0

I configured my timezone to Europe/Paris in php.ini. When executing date_default_timezone_get() I do get the correct value.

Then, I expect strftime('%x', date()) to output something like 16 novembre 2018 which is the French format. But instead, I get 11/16/2018 which looks like the US format.

Any idea why?

4
  • 2
    Setting the timezone doesn't set the locale. You need to look at secure.php.net/manual/en/function.setlocale.php or stackoverflow.com/questions/5075145/… which discusses putting it in the INI file Commented Nov 16, 2018 at 21:25
  • It doesn't seems to work. After setlocale('fr_Fr') the format is still the same. Commented Nov 16, 2018 at 21:41
  • 1
    On your server, run locale -a to see available locales. They are often named differently on different operating systems. fr_FR is most likely what you're looking for. Commented Nov 16, 2018 at 22:44
  • Possible duplicate of Change the language for date in php Commented Nov 16, 2018 at 22:45

3 Answers 3

2

The time zone has no effect on how dates and times are presented, for that you need to set the locale. There are no standards for locale names, but fortunately PHP's setlocale() function will take multiple locale names, stopping at the first successful one.

// just a few common name formats
setlocale(LC_TIME, ["fr_FR.utf8", "fr_FR@euro", "fr_UTF8", "fr_FR", "french"]);
echo strftime("%d %B %Y", time());
Sign up to request clarification or add additional context in comments.

4 Comments

Okay I finally noticed that fr_FR was not yet added to my server. I added it thanks to askubuntu.com/questions/76013/… and then using setlocale('fr_FR') did the trick. Thanks for your help :)
Just keep in mind it's safer to throw every name at it, if you plan to run this on any different servers!
On "there are no standards for locale names" - that is incorrect. IETF Language Tags are the standard, covered in BCP 47. More here. Agree on the other parts. Time zone and locale are orthogonal.
@MattJohnson I stand corrected. I should have said there are no standards consistently followed by OS makers.
1

I tried:

setlocale(LC_ALL, 'fr_utf8');


echo strftime("%d %B %Y", time());

and got:

16 novembre 2018

3 Comments

On my side I get 16 November 2018 (in English). But anyway, I have to stick to %x as I host an application which isn't mine and which uses this format.
''%x" is supposed to give you 11/16/2018 format: %x Preferred date representation based on locale, without the time Example: 02/05/09 for February 5, 2009. (php.net/manual/en/function.strftime.php)
%x in French would give you "16.11.2018"
-2

after setting the timezone to Europe/Paris, Use echo date('d-M-Y') and it will display your desired time. it worked for me

1 Comment

Hi, this shouldn't work, the user wishes something like 16 novembre 2018 (in French).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.