setlocale
和strftime
函数可以得到本地化的日期字符串。/* 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'";
setlocale
函数设定的是进程范围的地区设置(在使用多线程时可能会导致意外行为)。线程安全的替代方案是使用IntlDateFormatter
类。 - Matmarbon