我尝试使用setlocale()
Windows 上的函数将日期名称转换为其他语言,但没有成功。
<?php setlocale(LC_ALL, 'nl_NL');
echo date("l", strtotime($variable); ?>
有人可以替代setlocale()
吗?我使用 Codeigniter 框架。
我尝试使用setlocale()
Windows 上的函数将日期名称转换为其他语言,但没有成功。
<?php setlocale(LC_ALL, 'nl_NL');
echo date("l", strtotime($variable); ?>
有人可以替代setlocale()
吗?我使用 Codeigniter 框架。
您应该考虑使用intl
具有IntlDateFormatter
.
从文档中:
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL,IntlDateFormatter::FULL,'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
echo "First Formatted output is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL,IntlDateFormatter::FULL,'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
echo "Second Formatted output is ".$fmt->format(0);
哪个输出
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
nl_NL
是典型的 Unix 风格的语言环境名称。在 Windows 上,语言环境遵循不同的格式。你想要"nld"、"holland" 或 "netherlands"。
此外,date()
不支持区域设置。你可能想要strftime()
.
date
不根据语言环境格式化日期。strftime
做。
setlocale(LC_ALL, 'german');
echo (iconv('ISO-8859-2', 'UTF-8', strftime('%Y. %B %d. (%A)', mktime('0', '0', '0', '6', '18', '2010'))));
setlocale(LC_ALL, 'hungarian');
echo (iconv('ISO-8859-2', 'UTF-8', strftime('%Y. %B %d. (%A)', mktime('0', '0', '0', '6', '18', '2010'))));
您可以strftime
用于本地日期:
setlocale(LC_TIME, 'it_IT');
$timestamp = strtotime("31-12-2012");
echo strftime("%A", $timestamp);