gmdate
(PHP 4, PHP 5, PHP 7, PHP 8)
gmdate — 格式化 GMT/UTC 日期/时间
说明
同 date() 函数一样,只是返回的时间是格林威治标准时(GMT)。
参数
format
-
输出日期 string 的格式。参阅 date() 函数格式化选项。
timestamp-
可选的
timestamp 参数是一个 int 的 Unix
时间戳,如未指定或是 null ,参数值默认为当前本地时间。也就是说,其值默认为
time() 的返回值。
更新日志
| 版本 |
说明 |
| 8.0.0 |
现在 timestamp 允许为 null。
|
示例
示例 #1 gmdate() 示例
<?php
date_default_timezone_set("Europe/Helsinki");
echo date("M d Y H:i:s e", mktime(0, 0, 0, 1, 1, 1998)) . "\n";
echo gmdate("M d Y H:i:s e", mktime(0, 0, 0, 1, 1, 1998));
Jan 01 1998 00:00:00 Europe/Helsinki
Dec 31 1997 22:00:00 UTC
Anonymous ¶ 1 year ago
ATTN! The following code produces different result in PHP 7 and PHP 8!
gmdate('Y-m-d\TH:i:s', null);
In PHP 7 null in gmdate('Y-m-d\TH:i:s', null) translated as 0, although gmdate('Y-m-d\TH:i:s'); (w/o 2nd parameter specified) works as it should.
This issue is fixed in PHP 8.