gmdate()
gmdate() — Format a GMT/UTC date/time.
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.
What it does
Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).
Signature
gmdate(string $format, ?int $timestamp = null): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $format | string | The format of the outputted date string. See the formatting options for the date() function. |
| $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 formatted date string.
Example
A runnable snippet:
date_default_timezone_set("Europe/Helsinki"); echo date("M d Y H:i:s e", mktime(0, 0, 0, 1, 1, 1998)) . "\n"; echo gmdate("M d Y H:i:s e", mktime(0, 0, 0, 1, 1, 1998));
Output:
Jan 01 1998 00:00:00 Europe/Helsinki Dec 31 1997 22:00:00 UTC
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 gmdate() (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.