how to convert english date format to german date format in php

回眸只為那壹抹淺笑 提交于 2019-12-19 04:18:24

问题


Hi I have a date format like this

(in English format)

 15. July 2011

And I want to convert it in German format like this

15. Juli 2011

How to convert date format from one laguage to other language format?

My Code is

 $date = '15. July 2011';
 $newLocale = setlocale(LC_TIME, 'de_DE');
 $date = strftime('%d. %B %Y',$date);

But this is not converting I am getting July rather than Juli


回答1:


You could use setlocale function before calling date function:

$newLocale = setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');

EDIT: Quote from strftime docs:

This example will work if you have the respective locales installed in your system.




回答2:


If you have the Internationalization extension installed, you can use the IntlDateFormatter class.

It's really quite powerful and actually displays the date and time in the correct format for the locale you're targeting.

An example, for Germany might be:

// create format
$fmt = datefmt_create("de_DE", IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'Europe/Berlin', IntlDateFormatter::GREGORIAN);

// output (using current time)
echo datefmt_format($fmt , time());

Which outputs:

Dienstag, 29. November 2011



来源:https://stackoverflow.com/questions/8309865/how-to-convert-english-date-format-to-german-date-format-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!