如何在 PHP DateTime 对象中支持德语?

BM *_*FIQ 0 php wordpress datetime

如何更改德语格式的日期,例如星期二 = Dienstag(星期二 = 死)

$ed = new DateTime('03/20/2018');
$e_day_name = $ed->format('D');

var_dump( $e_day_name );
Run Code Online (Sandbox Code Playgroud)

字符串(3)“星期二”

我想要 [string(3) "Die"]

Mar*_*cel 6

这是一个简短的例子,在 Raunak Gupta 可能重复的评论中没有提到。它使用原生 IntlDateFormatter 类,自 PHP 5.3 起可用。在多语言环境中,您不必每次都设置默认时区。

// the date time object 
$date = new DateTime('2013-02-25'); 

// the international date formater object
$formatter = new IntlDateFormatter( 
    "de-DE", 
    IntlDateFormatter::LONG, 
    IntlDateFormatter::NONE, 
    "Europe/Berlin", 
    IntlDateFormatter::GREGORIAN, 
    "EEEE', der' dd. MMMM YYYY" 
); 

echo $formatter->format($date); // Montag, der 25. Februar 2013
Run Code Online (Sandbox Code Playgroud)

容易,嗯?;)

更多关于 IntlDateFormatter 类及其参数的 PHP 文档:http ://de2.php.net/manual/en/class.intldateformatter.php