可能的重复项:
使用不同的语言?
获取本地化月份列表
我从数据库中获取日期时间并按如下格式格式化:
$row['datetime'] = date('jS F Y',strtotime($row['datetime']));
这将输入一种格式:
28th March 2012
如何本地化月份的名称,以便对于法国用户,它将显示火星而不是三月?
谢谢
使用 setlocale
和 strftime
获取日期字符串的本地化版本。
PHP 文档示例 - 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).
对于社区的其他成员,strftime
尊重语言环境设置,并使用 glibc(在后台)。如果date
总是返回英语,strftime
将尊重setlocale
并为您提供预期的语言输出。