php - can't get date in german language

微笑、不失礼 提交于 2019-12-04 03:21:31

问题


I try to display a date in German but it doesn't work. I'm using PHP with XAMPP.

These are my approaches:

function get_Datetime_Now() {
setlocale (LC_TIME, "de_DE");
$tz_object = new DateTimeZone('Europe/Zurich');
$datetime = new DateTime();
$datetime->setTimezone($tz_object);     
return $datetime->format('l, d. F Y  ');
}

echo get_Datetime_Now();

It returns "Sunday, 09. February 2014" but I wan't "Sonntag, 09. Februar 2014" (German language).

I also tried this:

setlocale(LC_TIME, "de_DE");
echo strftime("%A, %d. %B %Y");

It also returns "Sunday, 09. February 2014". I saw many examples on the internet, which don't work (at least on my environment).

Are there settings that I should check?

I appreciate any help!

Thx in advance, shivan


回答1:


You are probably using a windows machine which has different language codes in PHP than a Unix based one.

Try:

setlocale(LC_TIME, 'de_DE', 'deu_deu');

This will first try to set it to 'de_DE' (Linux/Unix) and have the 'deu_deu' code as a fallback for windows (PHP Version >= 4.3).

Example in the german PHP documentation




回答2:


You can try with :

setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
echo strftime("%A, %d. %B %Y");

worked for me




回答3:


I just comment to thank Tim Bodeit, and if someone is looking to set the month in spanish, this is the code that worked to me:

setlocale(LC_TIME, 'es_ES', 'esp_esp');



回答4:


The locale parameters are others compared linux to windows

See here:

  • http://msdn.microsoft.com/en-us/library/39cwe7zf(v=vs.90).aspx
  • http://msdn.microsoft.com/en-us/library/cdax410z%28v=vs.90%29.aspx

Usually it's "DEU" or "GERMAN" under Win.



来源:https://stackoverflow.com/questions/21661218/php-cant-get-date-in-german-language

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