I am trying to output dates in the Italian format using date()
as follows:
<?php
setlocale(LC_ALL, 'it_IT');
echo date("D d M Y", $row['eventtime']);
?>
However, it is still coming out in the English format. What else could I do? Is there something wrong?
The solution has to be script specific and not server-wide.
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()
andstrftime()
functions instead ofdate()
.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With