English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP gmdate() Function Usage and Examples

PHP Date & Time Functions Manual

The gmdate() function formats a GMT/UTC date/time

Definition and Usage

gmdate()function accepts a format string as a parameter to specify the format for formatting the local GMT/UTC date/time.

is exactly the same as the date() function, except that it returns the time in Greenwich Mean Time (GMT). For example, when in China (GMT +0800) When running the following program, the first line displays “Jan 01 2000 00:00:00”and the second line displays “Dec 31 1999 16:00:00.

Syntax

gmdate($format, $timestamp)

Parameter

NumberParameters and Description
1

format (required)

This is a format string that specifies the format of the date string you want to output

2

timestamp (optional)

This is an integer value representing the timestamp of the required date

Return Value

PHP gmdate() function returns the current local time in the specified format/Date.

PHP Version

This function was first introduced in PHP version4introduced and can be used in all higher versions.

Online Example

Try the following demonstration ofgmdate()Usage of the Function-

<?php
   $date = gmdate("D M d Y");
   print("Date: ".$date);
?>
Test to see‹/›

Output Result

Date: Fri May 08 2020

Online Example

The following example uses this function to format the current date and print the sunrise using the result date/Sunset Information-

<?php
   $date = gmdate("H:i:s");
   $sun_info = date_sun_info($date, 20.5937, 78.9629);
   print_r($sun_info);
?>
Test to see‹/›

Output Result

Array
(
    [sunrise] => 4818
    [sunset] => 44087
    [transit] => 24453
    [civil_twilight_begin] => 3381
    [civil_twilight_end] => 45524
    [nautical_twilight_begin] => 1729
    [nautical_twilight_end] => 47176
    [astronomical_twilight_begin] => 98
    [astronomical_twilight_end] => 48807
)

Online Example

Now, call the function by passing a timestampgmdate()Function-

<?php
   $ts = 1022555568;
   $date = gmdate("D M d Y", $ts);
   print($date);
?>
Test to see‹/›

Output Result

Tue May 28 2002

Online Example

<?php
   date_default_timezone_set('UTC');   
   echo gmdate("l");
   echo ";\n";   
   echo gmdate('l dS of F Y h:i:s A');
   echo ";\n";
?>
Test to see‹/›

This produces the following result-

Wednesday
Wednesday 13th of May 2020 05:57:30 PM