7

Possible Duplicate:
strtotime With Different Languages?
Get list of localized months

I get the date time out of my database and format it like so:

$row['datetime'] = date('jS F Y',strtotime($row['datetime']));

This will put in a format:

28th March 2012

How can I localise the names of the months, so for french users it would display Mars instead of March?

Thanks

Community
  • 1
  • 1
beans
  • 1,765
  • 5
  • 25
  • 31

2 Answers2

8

Use setlocale and strftime to get a localized version of the date string.

Example from PHP Docs - http://php.net/manual/en/function.setlocale.php :

/* Set locale to Dutch */
setlocale(LC_ALL, 'nl_NL');

/* Output: vrijdag 22 december 1978 */
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));

/* try different possible locale names for german as of PHP 4.3.0 */
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
echo "Preferred locale for german on this system is '$loc_de'";
John Himmelman
  • 21,504
  • 22
  • 65
  • 80
  • 4
    But notice that [`setlocale` sets the locale process wide](http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes) (causing unexpected behavior with multiple threads when using multi-threading). Thread safe alternative: [IntlDateFormatter](http://php.net/manual/en/class.intldateformatter.php) – Matteo B. Sep 12 '14 at 09:25
1

Facile, utilise strftime et setlocale.

setlocale(LC_ALL, 'fr_FR.utf-8'); // ou LC_TIME
echo strftime('%A');
"lundi"

Fais attention a utiliser la version utf-8 si tu attends une sortie unicode, sinon, la version normale te donnera du iso-8859-1(5).

In English for the rest of the community, strftime respects the locale set, and uses the glibc (in the background). If date will always return english strftime will respect the setlocale and give you the expected output in your language.

greut
  • 4,305
  • 1
  • 30
  • 49