CakeFest 2024: The Official CakePHP Conference

gmdate

(PHP 4, PHP 5, PHP 7, PHP 8)

gmdateFormat a GMT/UTC date/time

Description

gmdate(string $format, ?int $timestamp = null): string

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).

Parameters

format

The format of the outputted date string. See the formatting options for the date() function.

timestamp

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 Values

Returns a formatted date string.

Changelog

Version Description
8.0.0 timestamp is nullable now.

Examples

Example #1 gmdate() example

When run in Finland (GMT +0200), the first line below prints "Jan 01 1998 00:00:00", while the second prints "Dec 31 1997 22:00:00".

<?php
echo date("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
echo
gmdate("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
?>

See Also

add a note

User Contributed Notes 1 note

up
0
bruno dot dasilva at odaseva dot com
6 days ago
with PHP7.4 (and probably below), when the 2d parameter $timestamp is null, then the date will be based on timestamp "0" (1970-01-01T00:00:00)
To Top