0

I want convert this date and time to german.

2019-12-22 19:45

to

Dienstag, 22. Dezember 2019 - 19:45

                $start = strtotime('2019-12-22 19:45');
                setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
                // create format

                // output (using current time)
                echo strftime(" %d. %B %Y",$start);

got this result which not in german :(

22. December 2019

I am using wordpress and making shortcode, getting data from api just for informations

UPDATE

I am using this code now but still not got result like i want.

setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
$dt = new DateTime($event->start , new DateTimeZone('Europe/Berlin'));    
echo $dt->format('d. F Y, H:i'); exit;

got this result

22. December 2019, 19:45

I tried this code but its not working.

Mohammad Umer
  • 542
  • 5
  • 27
  • What does `setlocale` return? Do other PHP scripts run on the same server that might call `setlocale` as well? The locale is per-process, not per-thread, so it's possible that another script changes the locale between your call to `setlocale` and `strftime`. – Max Vollmer Dec 18 '19 at 10:47
  • You might also run on a server that doesn't have the German locale, or the user your script runs under doesn't have permission to change the locale. You should investigate these things and then update your question with more info. – Max Vollmer Dec 18 '19 at 10:52
  • 1
    Does this answer your question? [PHP setlocale has no effect](https://stackoverflow.com/questions/10909911/php-setlocale-has-no-effect) – Max Vollmer Dec 18 '19 at 10:52

2 Answers2

1

I created a PHP extension for DateTime API called dt. You can find it here

Using it is very easy:

echo dt::create("2019-12-22 19:45","Europe/Berlin")->formatL('d. F Y, H:i','de');
//22. Dezember 2019, 19:45
Max Vollmer
  • 8,412
  • 9
  • 28
  • 43
jspit
  • 7,276
  • 1
  • 9
  • 17
  • It would be preferable to vote to close this question as duplicate of [PHP setlocale has no effect](https://stackoverflow.com/questions/10909911/php-setlocale-has-no-effect), and add your answer to the other question. – Max Vollmer Dec 18 '19 at 15:31
-1

I would recommend reading more about DateTime Formats https://www.php.net/manual/en/datetime.format.php Your solution:

setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
$time = date_create_from_format('U'; , '2019-12-22 19:45', new DateTimeZone('Europe/Berlin')); 

echo strftime(' %d. %B %Y', $time->getTimestamp());
NashPL
  • 461
  • 1
  • 4
  • 19