phpdatesetlocale

How to change date to spanish format with setlocale?


I trie to change the months name to spanish date but is not working. I don't know if I need to add a script in my head page. Here is my code:

<tbody>
    <?php
    setlocale(LC_ALL,"es_ES");
    for($i = 1; $i <=12; $i++):
      $dt = DateTime::createFromFormat('!m', $i);
      ?>
      <tr>
        <td><?= $dt->format("F");?></td>
        <td></td>
        <td></td>
      </tr>
    <?php endfor;?>
</tbody>

Solution

  • Try this:

    <?php
    setlocale(LC_TIME, 'es_ES', 'Spanish_Spain', 'Spanish');
    $date = date('F j, Y');
    echo strftime('%d %B %Y',strtotime($date));