PHP date - get name of the months in local language

后端 未结 5 1616
礼貌的吻别
礼貌的吻别 2020-12-11 00:46

I have this part of the function, which gives me name of the months in English. How can I translate them to my local language (Serbian)?

$month_name = date(\         


        
5条回答
  •  攒了一身酷
    2020-12-11 01:04

    For all who struggle with German (and de_DE), make sure you are using the right language code. Login to your server and run locale -a to see a list of all available ones. For me it shows:

    C
    C.UTF-8
    de_AT.utf8
    de_BE.utf8
    de_CH.utf8
    de_DE.utf8
    de_LI.utf8
    de_LU.utf8
    ...

    You need to use one of those codes.

    Then you can use:

    date_default_timezone_set('Europe/Berlin');
    setlocale(LC_ALL, 'de_DE.utf8');
    $date_now = date('Y-m-d');
    $month_available = strftime('%B %Y', strtotime($date_now));
    $month_next = strftime('%B %Y', strtotime($date_now.' +1 month'));
    
    

    and "März 2020" etc. get displayed correctly.

提交回复
热议问题