PHP Date function output in Italian

后端 未结 6 1196
误落风尘
误落风尘 2020-11-29 08:17

I am trying to output dates in the Italian format using date() as follows:



        
6条回答
  •  庸人自扰
    2020-11-29 08:53

    date() is not locale-aware. You should use strftime() and its format specifiers to output locale-aware dates (from the date() PHP manual):

    To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

    Regarding Anti Veeranna's comment: he is absolutely right, since 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);
    

提交回复
热议问题