gmstrftime()
What is the gmstrftime() function in PHP?The gmstrftime() function in PHP is a powerful tool that is used to format date and time in the UTC/GMT timezone. The
What is the gmstrftime() function in PHP?
The gmstrftime() function formatted a date and time as a string in the UTC/GMT timezone, using strftime()-style % specifiers whose text could be localized through the current locale (set with setlocale()). It behaved exactly like strftime() except that the output was always GMT rather than the server's local time.
Important:
gmstrftime()was deprecated in PHP 8.1 and removed in PHP 8.2. It no longer exists in modern PHP, so new code must use a replacement. The rest of this page explains the function for reference and shows the equivalents you should use today:gmdate()for fixed formats andIntlDateFormatterfor locale-aware output.
This page covers the original signature and format specifiers, the modern gmdate() replacement, how to map old % specifiers to the new format characters, and how to get locale-translated month/day names the right way.
Syntax
string gmstrftime(string $format, ?int $timestamp = null)$format— a string of%specifiers describing the desired output.$timestamp— an optional Unix timestamp. When omitted, the current time is used.
Common specifiers it accepted: %Y (4-digit year), %m (month, 01–12), %d (day, 01–31), %H (24-hour, 00–23), %M (minute), %S (second), %B (full month name), %A (full weekday name).
The modern replacement: gmdate()
Because gmstrftime() no longer exists, the direct replacement for fixed, machine-style formats is gmdate(). It also produces UTC output, but uses date()-style format characters (no %):
This outputs the current UTC date and time as YYYY-MM-DD HH:MM:SS, for example 2026-06-21 08:04:38.
Mapping old specifiers to gmdate()
| Meaning | gmstrftime() | gmdate() |
|---|---|---|
| 4-digit year | %Y | Y |
Month (01–12) | %m | m |
Day (01–31) | %d | d |
Hour (00–23) | %H | H |
| Minute | %M | i |
| Second | %S | s |
| Full month name | %B | F |
| Full weekday name | %A | l |
So gmstrftime("%A, %d %B %Y") becomes gmdate("l, d F Y").
Locale-aware UTC formatting
The one thing gmdate() does not do is translate month and weekday names into the current locale — gmdate() always returns English names. If you relied on gmstrftime() with setlocale() for translated output (e.g. French month names), use IntlDateFormatter from the intl extension instead:
<?php
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::NONE,
'UTC'
);
echo $formatter->format(time());
?>This prints the full date with French month and weekday names, in UTC — the modern, locale-safe equivalent of the old setlocale() + gmstrftime() pattern.
Why UTC formatting matters
Formatting in UTC (what gmstrftime() and now gmdate() do) is useful whenever you store or compare timestamps independently of the user's time zone. Logging, API responses, database values, and cross-region scheduling all benefit from a single, unambiguous reference. You convert to a local time zone only at display time — typically with the DateTime / DateTimeZone classes.
Conclusion
gmstrftime() provided a quick way to format UTC date and time with strftime()-style specifiers, but it has been removed in PHP 8.2. For fixed formats, replace it with gmdate() and translate the specifiers using the table above; for locale-translated month and day names, use IntlDateFormatter. To explore related functions, see strftime(), gmmktime(), and the broader PHP date and time guide.