PHP date, international month names?

Possible duplicate:
strtotime with different languages?
Get a list of localized months

I get the date in my database and format it like this:

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

It will look in the format:

 28th March 2012 

How can I localize the names of the months, so for French users it displays Mars instead of Mart?

thanks

+6
source share
2 answers

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

An example from PHP Docs is 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'"; 
+8
source

Facile, use strftime et setlocale .

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

Note that the la version utf-8 si tu utility is present in unicode unicode, sinon, la version normale te donnera du iso-8859-1 (5).

In English, for the rest of the community, strftime follows a set of locales and uses glibc (in the background). If date will always return to English strftime will respect setlocale and give you the expected result in your language.

+2
source

Source: https://habr.com/ru/post/915111/


All Articles