PHP 8.1.28 Released!

gmstrftime

(PHP 4, PHP 5, PHP 7, PHP 8)

gmstrftime根据区域设置格式化 GMT/UTC 时间/日期

警告

该函数自 PHP 8.1 起弃用。强烈建议不要依赖此函数。

此函数可以使用如下替代:

说明

gmstrftime(string $format, ?int $timestamp = null): string|false

行为和 strftime() 相同,只是返回的时间是格林威治标准时(GMT)。例如,在东部标准时(EST,GMT -0500)运行时,下面第一行显示“Dec 31 1998 20:00:00”,而第二行显示“Jan 01 1999 01:00:00”。

警告

此函数依赖于操作系统区域设置信息,这些信息可能彼此不一致,或者根本不能用。而是使用 IntlDateFormatter::format() 方法。

参数

format

See description in strftime().

timestamp

可选的 timestamp 参数是一个 int 的 Unix 时间戳,如未指定或是 null,参数值默认为当前本地时间。也就是说,其值默认为 time() 的返回值。

返回值

Returns a string formatted according to the given format string using the given timestamp or the current local time if no timestamp is given. Month and weekday names and other language dependent strings respect the current locale set with setlocale(). On failure, false is returned.

更新日志

版本 说明
8.0.0 现在 timestamp 允许为 null。

示例

示例 #1 gmstrftime() 例子

<?php
setlocale
(LC_TIME, 'en_US');
echo
strftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . "\n";
echo
gmstrftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . "\n";
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top