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.

Advertisements
This entry was posted in php.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s