Shadi Almosri Shadi Almosri - 1 year ago 72
PHP Question

PHP Date function output in Italian

Trying to output italian dates with date:

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...



Answer Source

date() is not locale-aware. You should use strftime() ant 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'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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download