PHP strftime outputs wrong format despite correct

2019-03-06 22:26发布

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?

3条回答
啃猪蹄的小仙女
2楼-- · 2019-03-06 22:59

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());
查看更多
\"骚年 ilove
3楼-- · 2019-03-06 23:02

I tried:

setlocale(LC_ALL, 'fr_utf8');


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

and got:

16 novembre 2018
查看更多
一纸荒年 Trace。
4楼-- · 2019-03-06 23:17

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

查看更多
登录 后发表回答