php “ru_RU”(俄语)setlocale 不适用于日期和时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18513742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"ru_RU" (russian) setlocale not working on date and time
提问by Ravi Sharma
I am trying to use Russian language with setlocale:
我正在尝试在 setlocale 中使用俄语:
setlocale(LC_TIME,"ru_RUS.utf8");
echo strftime("%A, %B %d", time());
Output is : Thursday, August 29
输出是: 8 月 29 日,星期四
Expected is : четверг, Август 29
预期是 : четверг, Август 29
Any help would be highly appreciated.
任何帮助将不胜感激。
回答by Ravi Sharma
Found it! if you are using Linux hosting then try:
找到了!如果您使用的是 Linux 主机,请尝试:
setlocale(LC_ALL, 'ru_RU.UTF-8');
will works fine. In case you are using windows hosting then try:
会正常工作。如果您使用的是 Windows 主机,请尝试:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
setlocale(LC_ALL, 'russian');
回答by Visman
For the Russian locale and UTF-8 it is possible to use such code. Work in Widowsand Unix.
对于俄语语言环境和 UTF-8,可以使用此类代码。在寡妇和Unix 中工作。
header('Content-type: text/html; charset=utf-8');
$locale_time = setlocale (LC_TIME, 'ru_RU.UTF-8', 'Rus');
function strf_time($format, $timestamp, $locale)
{
$date_str = strftime($format, $timestamp);
if (strpos($locale, '1251') !== false)
{
return iconv('cp1251', 'utf-8', $date_str);
}
else
{
return $date_str;
}
}
echo strf_time("%A, %B %d", time(), $locale_time);
Result:
结果:
вторник, Октябрь 13
回答by Joop Eggen
var_dump(setlocale(LC_ALL, 'ru_RU.utf8'));
The function setlocale returns the result of the system call. I think it should be RU, not Ru.
函数 setlocale 返回系统调用的结果。我认为应该是RU,而不是Ru。