MySQL日期格式用德语

时间:2016-12-19 23:15:46

标签: php mysql date datetime

我的查询中有一个Date-Ouput和format-string:

$date = $sql->getValue("date");
$datenew = DateTime::createFromFormat('Y-m-d', $date);
$dateex = $datenew->format('l, d.m.Y');

// Output: Monday, 19.12.2016

有没有办法用德语(“Montag”)获得“星期一”?

1 个答案:

答案 0 :(得分:4)

是。您可以使用setlocale()

setlocale(LC_TIME, 'de_DE', 'deu_deu');
$date =  date('l, d.m.Y');
echo $date; //outputs: Montag, 19.12.2016

查看:http://php.net/manual/en/function.setlocale.php

或者您可以使用以下解决方法:

$date =  date('l, d.m.Y');
$arrDate = explode(",",$date);
$weekDay = "";

switch($arrDate[0])
{
    case 'Monday':    $weekDay = 'Montag, ';
                      break;
    case 'Tuesday':   $weekDay = 'Dienstag, ';
                      break;
    case 'Wednesday': $weekDay = 'Mittwoch, ';
                      break;
    .
    .
    .
    case 'Sunday' :   $weekDay = 'Sonntag, ';
                      break;

}

echo $weekDay.$arrDate[1];