PHP gmdate () function
PHP date/time function
Definitions 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 Standard (GMT).
Grammar
Gmdate (Format,timestamp)
Parameter description
Format is optional. Specify how the results are returned.
Timestamp optional.
Tips and comments
Note: Before PHP 5.1.0, a negative timestamp (the date before 1970) does not work on some systems (for example, Windows).
Example
Example 1
When running the following program in China (GMT +0800), the first line shows "01 2000 00:00:00", while the second line shows "Dec 31 1999 16:00:00".
<?php Tutorial
echo 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:
01 2000 00:00:00
Dec 31 1999 16:00:00
Example 2
<?php
Echo ("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_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 ():
Tuesday
Tuesday 24th of January 2006 02:41:22 PM
Oct 3,1975 is on a Friday
Tue, 2006 14:41:22 CET
1975-10-03t00:00:00+0100
Result with Gmdate ():
Tuesday
Tuesday 24th of January 2006 01:41:22 PM
Oct 3,1975 is on a Thursday
Tue , 2006 13:41:22 GMT
1975-10-02t23:00:00+0000