HTTP标头中使用的日期/时间格式 [英] The date/time format used in HTTP headers

查看:1110
本文介绍了HTTP标头中使用的日期/时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个RFC描述了现代HTTP头中用于日期/时间的格式,例如Last-Modified和If-Modified-Since,以及如何根据这种格式在PHP中生成日期/时间字符串?

Which RFC describes the format used for date/time in the modern time HTTP headers, like "Last-Modified" and "If-Modified-Since", and how to generate a date/time string in PHP according to such format?

某些来源指向RFC 2822,由 DateTime 类,正在使用 D,d MYH:i:s O 格式,但从我的测试中,此格式产生 +0000 而不是 GMT 。我尝试过其他时区说明符,但是最后没有一个表达式似乎把 GMT 最接近的结果与 UTC 。然而,如Firebug所示,所有网站都使用HTTP标头中的 GMT 而不是 +0000 UTC

Some sources point to RFC 2822, which, as indicated by DateTime class, is using D, d M Y H:i:s O format, but from my tests, this format produces +0000 instead of GMT at the end. I tried other timezone specifiers but none of them seems to put GMT at the end, the closest result I got was with UTC. However, as was shown by Firebug, all sites are using GMT in HTTP headers and not +0000 or UTC.

那么真正使用什么格式,如何以与其他网站相同的方式格式化日期/时间?

So what format is really used and how do I format date/time in the same way as other sites do?

推荐答案

如您所见, 上次修改标头在 RFC2616 格式

As you can see here, Last-Modified header has datetimes in RFC2616 format.

14.29上次修改 ,您可以看到日期格式应为:

In section 14.29 Last-Modified you can see that date format should be:

"Last-Modified" ":" HTTP-date

其使用的一个例子是

An example of its use is

Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT

另一个q来自RFC2616 阅读更多

Another quote from RFC2616 read more :


所有HTTP日期/时间戳都必须在格林尼治标准时间(GMT)中表示,无一例外。

All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception.

在PHP中,您可以使用格式 D,d MYH:i:s T 如果您使用函数 gmdate()它总是以GMT偏移/时区返回datetime:

In PHP you can use format D, d M Y H:i:s T if you use function gmdate() which always returns datetime in GMT offset/timeszone:

echo gmdate('D, d M Y H:i:s T');

如果您希望使用 DateTime

$dt = new DateTime('UTC');
#$dt = new DateTime('2013-01-01 12:00:00', new DateTimezone('UTC'));
echo $dt->format('D, d M Y H:i:s \G\M\T');

这篇关于HTTP标头中使用的日期/时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆