PHP日期函数输出为意大利语 [英] PHP Date function output in Italian
问题描述
尝试以日期输出意大利日期:
Trying to output italian dates with date:
<?php
setlocale(LC_ALL, 'it_IT');
echo date("D d M Y", $row['eventtime']);
?>
但它仍然以英文出现,任何想法我还能做什么或出什么问题?它必须是脚本特定的而不是服务器端的...
But it's still coming out in English, any ideas of what else i can do or what's wrong? it has to be script specific and not server wide...
谢谢
Shadi
推荐答案
date()
不是区域设置。您应该使用 strftime()
使用其格式说明符来输出区域设置感知日期(从 date()
PHP手册):
date()
is not locale-aware. You should use strftime()
ant its format specifiers to output locale-aware dates (from the date()
PHP manual):
格式化日期其他语言,
您应该使用setlocale ()
和
strftime()
功能而不是
date()
。
关于anti.veeranna的评论:他是对的。您必须非常小心设置区域设置,因为它们有时不限于当前的脚本范围。最好的方法是:
Regarding anti.veeranna's comment: he's absolutely right. You have to be very careful with setting locales as they are sometimes not limited to the current script scope. The best way would be:
$oldLocale = setlocale(LC_TIME, 'it_IT');
echo utf8_encode( strftime("%a %d %b %Y", $row['eventtime']) );
setlocale(LC_TIME, $oldLocale);
这篇关于PHP日期函数输出为意大利语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!