2012-05-07 45 views

回答

8

使用setlocalestrftime來獲取日期字符串的本地化版本。從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, '[email protected]', 'de_DE', 'de', 'ge'); 
echo "Preferred locale for german on this system is '$loc_de'"; 
+3

但請注意,['setlocale'設置區域進程範圍](http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes)(使用多線程時導致意外的行爲多線程)。線程安全的替代方法:[IntlDateFormatter](http://php.net/manual/en/class.intldateformatter.php) – Matmarbon

2

簡易,利用strftimesetlocale

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

FAIS注意力utiliser LA版本UTF-8司徒出席UNE出擊unicode的,興農,LA版本師範學校TE donnera杜ISO-8859-1(5)。

對於其他社區的英語,strftime尊重區域設置,並使用glibc(在後臺)。如果date將始終返回英文strftime將尊重setlocale並以您的語言爲您提供預期輸出。

+17

英語請。這是一個**英文**網站... – Neal

+0

啊,打我也是吧! –

+0

請原諒我的法語,這很誘人。 – greut