German Umlauts in strftime date-formatting - correct utf-8 encoding?

matt picture matt · Oct 1, 2012 · Viewed 8.7k times · Source

I'm creating a german date format like this with PHP 14. März 2012 (which is March 14th 2012).

I'm working with $date[0] that contains a unix timestamp and I convert it like this to a readable german date.

$date_day_month = strftime('%d. %B', $date[0]);
$date_year = strftime('%Y', $date[0]);

echo $date_day_month . $date_year;

However I somehow get a question mark for the Umlaut ä like this

14. M�rz 2012

Why is that and how can I fix this? Thanks in advance.

Answer

lorem monkey picture lorem monkey · Aug 14, 2013

In my case a simple change of the locale did the trick.

Instead of:

setlocale(LC_TIME, "de_DE");

Use:

setlocale(LC_TIME, "de_DE.UTF-8");