strftime()
strftime() — Format a local time/date according to locale settings.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
The PHP manual marks this function as deprecated (since PHP 8.1, use IntlDateFormatter::format() instead): do not use it in new code.
What it does
Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale().
Signature
strftime(string $format, ?int $timestamp = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $format | string | The following characters are recognized in the format parameter string format Description Example returned values Day --- --- %a An abbreviated textual representation of the day Sun through Sat %A A full textual representation of the day Sunday through Saturday %d Two-digit day of the month (with leading zeros) 01 to 31 %e Day of the month, with a space preceding single digits. Not implemented as described on ... |
| $timestamp | ?int | The optional timestamp parameter is an int Unix timestamp that defaults to the current local time if timestamp is omitted or null. In other words, it defaults to the value of time(). |
Return value
Returns a string formatted according format using the given timestamp or the current local time if no timestamp is given. Month and weekday names and other language-dependent strings respect the current locale set with setlocale(). The function returns false if format is empty, contains unsupported conversion specifiers, or if the length of the returned string would be greater than 4095.
Example
A runnable snippet:
setlocale(LC_TIME, "C"); echo strftime("%A"); setlocale(LC_TIME, "fi_FI"); echo strftime(" in Finnish is %A,"); setlocale(LC_TIME, "fr_FR"); echo strftime(" in French %A and"); setlocale(LC_TIME, "de_DE"); echo strftime(" in German %A.\n");
Changelog
| Version | Change |
|---|---|
| 8.0.0 | timestamp is nullable now. |
See also
setlocale(), mktime(), strptime(), gmstrftime()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page strftime() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.