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
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'";
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With