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

ParameterTypeWhat it takes
$formatstringThe format of the outputted date string. See the formatting options for the date() function.
$timestamp?intThe 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

VersionChange
8.0.0timestamp is nullable now.

See also

date(), mktime(), gmmktime()

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.