Home > Article > Backend Development > The difference between php function date and gmdate_PHP tutorial
PHP has two time formatting functions: date() and gmdate(). The description in the official documentation is date - formats a local time/date gmdate - formats a GMT/UTC date/time, and returns Green U.K. Standard Time (GMT).
For example, our current time zone is +8, then the time returned by the server running the following script should be like this:
The current time is assumed to be 2007-03-14 12:15:27
The code is as follows | Copy code | ||||
echo gmdate(‘Y-m-d H:i:s’, time()); The output is: 2007-03-14 04:15:27
|
PHP Date/Time constants
PHP: Indicates the earliest PHP version that supports this constant.
Constant Description PHP
DATE_ATOM atomic clock format (eg: 2005-08-15T16:13:03+0000)
DATE_COOKIE HTTP Cookies format (eg: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_ISO8601 ISO-8601 (eg: 2005-08-14T16:13:03+0000)
DATE_RFC822 RFC 822 (eg: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_RFC850 RFC 850 (eg: Sunday, 14-Aug-05 16:13:03 UTC)
DATE_RFC1036 RFC 1036 (eg: Sunday, 14-Aug-05 16:13:03 UTC)
DATE_RFC1123 RFC 1123 (eg: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_RSS RSS (eg: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_W3C World Wide Web Consortium (eg: 2005-08-14T16:13:03+0000)
echo gmdate(‘Y-m-d H:i:s’, time() + 3600 * 8);
gmdate(): Returns the "custom format" time of the current GMT standard time, which has nothing to do with the time zone set by the PHP system.
Example 1
代码如下 | 复制代码 |
echo date("M d Y H:i:s", mktime (0,0,0,1,1,2000)); 输出: Jan 01 2000 00:00:00 |
The code is as follows | Copy code |
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: Jan 01 2000 00:00:00 Dec 31 1999 16:00:00 |
例子 2
代码如下 | 复制代码 | ||||
"); echo(date("l") . " "); echo(date("l dS of F Y h:i:s A") . " "); echo("Oct 3,1975 was on a ".date("l", mktime(0,0,0,10,3,1975))." "); echo(date(DATE_RFC822) . " "); echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . " "); echo("Result with gmdate(): "); echo(gmdate("l") . " "); echo(gmdate("l dS of F Y h:i:s A") . " "); echo("Oct 3,1975 was on a ".gmdate("l", mktime(0,0,0,10,3,1975))." "); echo(gmdate(DATE_RFC822) . " "); echo(gmdate(DATE_ATOM,mktime(0,0,0,10,3,1975)) . " "); ?>
|