gmstrftime()
gmstrftime() — Format a GMT/UTC 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
Behaves the same as strftime() except that the time returned is Greenwich Mean Time (GMT). For example, when run in Eastern Standard Time (GMT -0500), the first line below prints "Dec 31 1998 20:00:00", while the second prints "Jan 01 1999 01:00:00".
Signature
gmstrftime(string $format, ?int $timestamp = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $format | string | See description in strftime(). |
| $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 to the given format string 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(). On failure, false is returned.
Example
A runnable snippet:
setlocale(LC_TIME, 'es_ES.UTF-8'); date_default_timezone_set('EST'); echo strftime("%B %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . "\n"; echo gmstrftime("%B %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98));
Output:
Deprecated: Function strftime() is deprecated since 8.1, use IntlDateFormatter::format() instead in script on line 6 diciembre 31 1998 20:00:00 Deprecated: Function gmstrftime() is deprecated since 8.1, use IntlDateFormatter::format() instead in script on line 7 enero 01 1999 01:00:00
Changelog
| Version | Change |
|---|---|
| 8.0.0 | timestamp is nullable now. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page gmstrftime() (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.