Last Updated: February 25, 2016
·
751
· kanuj

Non-english dates with strftime

Working on a multi-lingual project and struggling to get strftime() to return non-English date names in PHP? Your server probably doesn’t have the locales you’re looking for. Write this in a terminal:

locale -a

This should return you the list of installed locales. If you don’t find yours in there, you can install it:

sudo locale-gen <locale_name>

For eg., for French you’d write:

sudo locale-gen fr_FR.utf8

Now use strftime to get the localised date:

setlocale(LC_TIME, “fr_FR.utf8“);
echo strftime(” The time is: %A %B %C”);

Neat.