php - How to change date language?
611
<table >
<tr><td colspan="2">Vergangene Projekte</td></tr>
<?php $query = "SELECT * FROM posts WHERE project = 1 && project_date <= CAST(CURRENT_TIMESTAMP AS DATE)ORDER BY date DESC";
if(!$query){
die("Konnte nicht mit Data Base verbinden");}
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($result)){
setlocale(LC_ALL, 'de_DE'); // using german language works
$premier = new DateTime($row['project_date']);
echo "<tr><td>" .strftime("%B", $premier->getTimestamp()). "</td><td class=\"project_title\">
<a class=\"title\" href=\"projekt_info.php?projekt=" .urlencode($row["id"]) ."\">"
.$row['title']. "</a></td></tr>";}
?>
</table>
Ok I modified the code to show all of it and also inserted the suggestions and now it works just fine!! Perfect
Cheers Chris
Answer
Solution:
First off make sure that indeed
fr_FR
is installed on the machine for your script to use.Try to use
locale -a
on your terminal to check.Second, since
DateTime
only works on english, usestrftime()
on that, and you're using it without the timestamp.Sidenote: as Fred said in the comments, this is just a fragment because your markup is a bit off (missing tags, etc, and most likely this is inside a loop).
Answer
Solution:
A bit late but I prefer using IntlDateFormatter which is system-locale independant and output is guaranteed to be in UTF-8:
(see ICU's documentation for a custom format - the last argument of IntlDateFormatter constructor)