2014-09-29 59 views
1
<table class="projects"> 
    <tr><td class="title" 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> 

好的我修改了代码来显示所有的代码,并插入了建议,现在它工作得很好!完美如何更改日期语言?

干杯 克里斯

+0

你可以尝试添加'setlocale(LC_TIME,'fr_FR');' – 2014-09-29 13:53:22

+0

另外,是你的完整代码?如果是这样,就会有不少事情丢失。表标签,例如数据抓取。 – 2014-09-29 13:57:07

+0

并确保'fr_FR'语言环境确实安装在机器中。 'locale -a' – Ghost 2014-09-29 13:59:24

回答

3

首先确保确实fr_FR安装在机器上的脚本中使用。

尝试在终端上使用locale -a进行检查。

其次,由于DateTime只适用于英文,因此请使用strftime(),并且您没有使用时间戳。

setlocale(LC_ALL, 'fr_FR'); 
$premier = new DateTime($row['project_date']); 
echo "<tr><td>" .strftime("%B", $premier->getTimestamp()). "</td><tr>"; 
            // ^^ feed the timestamp 

旁注:弗雷德在评论中说,这仅仅是一个片段,因为你的标记是有点过(缺少的标记等,并最有可能的,这是一个循环内)。

0

有点晚了,但我更喜欢使用IntlDateFormatter这是系统区域设置独立的输出是保证在UTF-8:

$datefmt = new IntlDateFormatter('de_DE', NULL, NULL, NULL, NULL, 'LLLL'); 
while($row = mysqli_fetch_array($result)) { 
    # ... 
    echo "<tr><td>" . $datefmt->format($premier). "</td>"/*...*/; 
    # ... 

(见ICU对a custom format文档 - IntlDateFormatter构造函数的最后一个参数)