search

Home  >  Q&A  >  body text

PHP date - get month name in local language

<p>I have this part of the function which gives me the name of the month in English. How can I translate them into my local language (Serbian)? </p> <pre class="brush:php;toolbar:false;">$month_name = date('F', mktime(0, 0, 0, $i));</pre> <p>where <code>$i</code> is the month number (values ​​1 - 12). See also PHP:mktime. </p>
P粉515066518P粉515066518536 days ago655

reply all(2)I'll reply

  • P粉037215587

    P粉0372155872023-08-25 09:15:26

    You should use setlocale() and strftime():

    setlocale(LC_TIME, 'sr_CS');
    $month_name = strftime('%B', mktime(0, 0, 0, $i));

    reply
    0
  • P粉445714413

    P粉4457144132023-08-25 00:30:37

    You should use setlocale():

    setlocale(LC_TIME, 'fr_FR');
    $month_name = date('F', mktime(0, 0, 0, $i));

    In this example it will be set to French. In your case it should be one of the following:

    1. sr_BA - Serbian (Montenegro)
    2. sr_CS - Serbian (Serbia)
    3. sr_ME - Serbian (Serbia and Montenegro)

    reply
    0
  • Cancelreply