如何在PHP DateTime对象中支持德语? [英] How can I support the German language in PHP DateTime object?

查看:73
本文介绍了如何在PHP DateTime对象中支持德语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I change the days in German format like Tuesday = Dienstag (Tue = Die)

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

var_dump( $e_day_name );




string(3) Tue

string(3) "Tue"

我想要[string(3) Die]

I want [string(3) "Die"]


推荐答案

这是一个简短的示例,Raunak Gupta可能重复的评论中未提及。它使用本机的IntlDateFormatter类,该类自PHP 5.3起可用。您不必在多语言环境中每次都设置默认时区。

Here is a short example, which is not mentioned in the possible duplicate comment by Raunak Gupta. It uses the native IntlDateFormatter class, which is available since PHP 5.3. You don 't have to set the default timezone every time in a multilanguage environment.

// 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

容易吗? ;)

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

More about the IntlDateFormatter class and its parameters in the PHP documentation: http://de2.php.net/manual/en/class.intldateformatter.php

这篇关于如何在PHP DateTime对象中支持德语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆