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

后端 未结 2 739
感动是毒
感动是毒 2021-01-06 18:04

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

         


        
相关标签:
2条回答
  • 2021-01-06 18:17

    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.

    0 讨论(0)
  • 2021-01-06 18:17

    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

    0 讨论(0)
提交回复
热议问题