0

I do not understand why the locale set in config.yml symfony is not applied on my OVH server.

I tried direcly to convert date in php without the framework and here are my results :

setlocale (LC_TIME, 'fr_FR.utf8');

echo strftime ("% A% e% B% Y", mktime (0, 0, 0, 12, 22, 1978));

$today = new \datetime();
print_r ($today-> format ('l d F Y - H:i'));

return : "vendredi 22 décembre 1978" "Tuesday 27 March 2018 - 18:49"

I would like only "vendredi 22 décembre 1978"

I don't want to use https://www.simonholywell.com/post/2015/07/international-php-dates-with-intl/ because I don't want to convert dates each times I need to display a date.

I don't have this problem on others hosters. Only on OVH webhosting.

Thank tou for you help

bingo
  • 150
  • 3
  • 10

1 Answers1

0

There is a workaround on this article from the same blog consisting to transform the date object to a timestamp, then format it according to locale settings with strftime:

setlocale(LC_TIME, 'fr_FR')

echo strftime("%A %e %B %Y", (new \DateTime())->getTimestamp());

Carbon, a library extending DateTime, handles this in its formatLocalized method:

echo strftime("%A %e %B %Y", strtotime((new \DateTime())->format('Y-m-d H:i:s')));

I don't know about a reason to use strtotime and DateTime::format instead of just DateTime::getTimestamp (both are limited to dates after the UNIX epoch because of strftime), but I guess you'll have to convert the DateTime in a way or another.

LEI
  • 316
  • 3
  • 14