我的查询中有一个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”)获得“星期一”?
答案 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];