tags:

views:

542

answers:

3

Hiya,

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

Thanks

Shadi

+1  A: 

it_IT locale has to be installed/enabled by your server admin, otherwise this will not work.

So, Jonathan's solution is probably the best.

Anti Veeranna
I have full access to the server, any ideas where i can check which local are installed?
Shadi Almosri
by typing 'locale -a' if that server is running some variant of Linux/BSD.
Anti Veeranna
+5  A: 

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 strftime("%a %d %b %Y", $row['eventtime']); 
setlocale(LC_TIME, $oldLocale);
Stefan Gehrig
Perfect, that worked :)
Shadi Almosri
Keep in mind that setlocale is not script specific, it is thread specific, so it is possible that the locale changes 'underneath' you.http://ee.php.net/setlocale explains it too.
Anti Veeranna