Definition and Usage
The Gmdate () function formats the GMT/UTC date/time.
Similar to the date () function, the difference is that the time returned is Greenwich Mean Time (GMT).
Grammar
Parameters |
Description |
Format |
Optional. Specifies how the results are returned. |
Timestamp |
Optional. |
Hints and notes
Note: Before PHP 5.1.0, negative timestamps (dates before 1970) do not work under some systems (for example, Windows).
ExampleExample 1
When the following program is run in China (GMT +0800), the first line shows "Jan 01 2000 00:00:00" and the second line shows "Dec 31 1999 16:00:00".
<?phpecho date ("M D y h:i:s", Mktime (0,0,0,1,1,2000)), Echo gmdate ("M D y h:i:s", Mktime (0,0,0,1,1,2000));? >
Output:
Jan 00:00:00dec 31 1999 16:00:00
Example 2
<?phpecho ("Result with date (): <br/>"); Echo (Date ("L"). "<br/>"); Echo (Date ("L DS \of F Y h:i:s A"). "<br/>"); Echo ("Oct 3,1975 is on a". Date ("L", Mktime (0,0,0,10,3,1975)). " <br/> "); Echo (Date (date_rfc822). "<br/>"); Echo (Date (Date_atom,mktime (0,0,0,10,3,1975)). "<br/><br/>"); Echo ("Result with Gmdate (): <br/>"); Echo (Gmdate ("L"). "<br/>"); Echo (Gmdate ("L DS \of F Y h:i:s A"). "<br/>"); Echo ("Oct 3,1975 is on a". Gmdate ("L", Mktime (0,0,0,10,3,1975)). " <br/> "); Echo (Gmdate (date_rfc822). "<br/>"); Echo (Gmdate (Date_atom,mktime (0,0,0,10,3,1975)). "<br/>");? >
Output:
Result with date (): Tuesdaytuesday 24th of January 2006 02:41:22 Pmoct 3,1975 is on a fridaytue, Jan 2006 14:41:22 CET1 975-10-03t00:00:00+0100result with Gmdate (): Tuesdaytuesday 24th of January 2006 01:41:22 Pmoct 3,1975 is on a ThursdayTue , Jan 2006 13:41:22 gmt1975-10-02t23:00:00+0000
PHP gmdate () function