可能重複:
strtotime With Different Languages?
Get list of localized monthsPHP日期,國際月份名稱?
我得到的日期時間我的數據庫中,並對其進行格式化,像這樣:
$row['datetime'] = date('jS F Y',strtotime($row['datetime']));
這將會把一個格式:
28th March 2012
如何本地化月份的名稱,因此法國用戶將顯示火星而不是3月?
由於
可能重複:
strtotime With Different Languages?
Get list of localized monthsPHP日期,國際月份名稱?
我得到的日期時間我的數據庫中,並對其進行格式化,像這樣:
$row['datetime'] = date('jS F Y',strtotime($row['datetime']));
這將會把一個格式:
28th March 2012
如何本地化月份的名稱,因此法國用戶將顯示火星而不是3月?
由於
使用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, '[email protected]', 'de_DE', 'de', 'ge');
echo "Preferred locale for german on this system is '$loc_de'";
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
並以您的語言爲您提供預期輸出。
但請注意,['setlocale'設置區域進程範圍](http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes)(使用多線程時導致意外的行爲多線程)。線程安全的替代方法:[IntlDateFormatter](http://php.net/manual/en/class.intldateformatter.php) – Matmarbon