The PHP function strftime() formats a date/time value according to the sytem's locale, for example, to the web server's local settings. Generally, the language of the system is automatically used. However, this can be overridden using setlocale(). Localizing Dates Using strftime() (strftime.php)<?php 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 Français: %c'); ?> The function strftime() expects a format string (as does date()) in which it accepts a large number of special symbols. Table 3.2 contains a full list.
Whenever it says standard format in Table 3.2, 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 3.1. Also take a look at Figure 3.2, 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. Figure 3.1. The current date in different locales.Figure 3.2. This particular system does not seem to support locales. |