Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Date, International month names? [duplicate]

Tags:

php

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

like image 640
beans Avatar asked May 07 '12 17:05

beans


2 Answers

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'";
like image 131
John Himmelman Avatar answered Oct 08 '22 16:10

John Himmelman


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.

like image 26
greut Avatar answered Oct 08 '22 15:10

greut