Automatically Localizing Dates

The PHP function strftime() formats a date/time value according to the sytem's locale, for example, to the web server's local settings.

setlocale(LC_TIME, 'en_US');
echo strftime('In (American) English: %c<br />');

Generally, the language of the system is automatically used. However, this can be overridden using setlocale().

Localizing Dates Using strftime()

  setlocale(LC_TIME, 'en_US');
  echo strftime('In (American) English: %c<br />');
  setlocale(LC_TIME, 'en_gb');
  echo strftime('In (British) English: %c<br />');
  setlocale(LC_TIME, 'de_DE');
  echo strftime('Auf Deutsch: %c<br />');
  setlocale(LC_TIME, 'fr_FR');
  echo strftime('En Francais: %c');

The function strftime() expects a format string (as does date()) in which it accepts a large number of special symbols. Table contains a full list.

Formatting Symbols for strftime()

Symbol Description


Day of week (abbreviated)


Day of week

%b or %h

Month (abbreviated)




Date and time in standard format




Day of month (from 01 to 31)


Date in abbreviated format (mm/dd/yy)


Day of month as a two-character string (from ' 1' to '31')


Year according to the week number, two digits


Year according to the week number, four digits


Hour (from 00 to 23)


Hour (from 01 to 12)


Day of year (from 001 to 366)


Month (from 01 to 12)


Minute (from 00 to 59)


Newline (\n)


am or pm (or local equivalent)


Time using a.m./p.m. notation


Time using 24 hours notation


Second (from 00 to 59)


Tab (\t)


Time in hh:ss:mm format


Day of week (from 1Mondayto 7Sunday)


Week number (Rule: The first Sunday is the first day of the first week.)


Week number (Rule: The first week in the year with at least four days counts as week number 1.)


Day of week (from 0Sunday to 6Saturday)


Week number (Rule: The first Monday is the first day of the first week.)


Date in standard format (without the time)


Time in standard format (without the date)


Year (two digits)


Year (four digits)

%z or %Z

Time zone

Whenever it says standard format in table, the formatting symbol gets replaced by the associated value according to the local setting. The preceding code changes the locale several times using setlocale() and then calls strftime(). Note the differences that can be seen in figure. Also take a look at figure, in which the same script was executed on a Windows machine. According to the documentation, most of strftime() also works on Windows, but on some configurations changing the locale just does not seem to work. Therefore, it is very important to test first whether the system supports localized dates.

The current date in different locales.

This particular system does not seem to support locales.