Search code examples
phpdatelocalization

PHP date() in foreign languages - e.g. Mar 25 Aoû 09


I have a script that needs to display date data to an international audience - e.g.

"submitted Tue 25 Aug 09"

Is there an easier/cleaner way to get this converted to the French(etc) equivalent "Mar 25 Aoû 09" than:

Setting a constant LANG and a $LANGUAGES array of include files & :

if(LANG != 'EN')
{
include $LANGUAGES['LANG'];
}

& then the included file maps the days & months & replaces for the appropriate locale?


Solution

  • I think you can't get away from doing so without setting LOCALE:

    <?php
    setlocale(LC_ALL, 'fr_FR');
    
    echo strftime("%A %e %B %Y");
    ?> 
    

    Some details on strftime: https://www.php.net/manual/en/function.strftime.php