Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - can't get date in german language

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

like image 911
user2871190 Avatar asked Feb 09 '14 15:02

user2871190


People also ask

How to format date with PHP?

Change YYYY-MM-DD to DD-MM-YYYY In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate));

How can I get current date in YMD in PHP?

date('Y-m-d H:i:s') . See the manual for more. Show activity on this post. date("Y-m-d H:i:s"); // This should do it.

How can set static date in PHP?

use a variable $datetime = date('Y-m-d H:i:s') .. it will store current date and time in $variable , and use $variable in all 50 insert queries.. so all time it will be same..

What is the date in PHP?

The date function in PHP is used to format the timestamp into a human desired format. The timestamp is the number of seconds between the current time and 1st January, 1970 00:00:00 GMT. It is also known as the UNIX timestamp.


1 Answers

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

like image 121
Tim Bodeit Avatar answered Nov 08 '22 06:11

Tim Bodeit