什么是有效的RFC1123日期格式 [英] What is valid RFC1123 date format

查看:623
本文介绍了什么是有效的RFC1123日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理返回过期标头的服务.该服务将在不同时区工作.因此,我们需要一种返回GMT以外的其他时区的方法.

I am working on a service which returns expires header. The service will be working across different timezone. So we need a way to return other timezones than GMT.

我知道http标头必须遵循RFC1123标准日期格式.因此该服务返回的日期如下所示-

I know that the http header have to follow RFC1123 standard date format. So the service returns date like below -

星期五,2019年3月1日格林尼治标准时间15:00:00

Fri, 01 Mar 2019 15:00:00 GMT

我需要按以下格式返回日期.

What I need is return the date in below format.

2019年3月1日星期五15:00:00 +0530

Fri, 01 Mar 2019 15:00:00 +0530

这是RFC1123日期格式的有效日期吗?

Is this a valid date for RFC1123 date format?

推荐答案

我猜您正在使用 old 过时

I guess you are using the old and obsolete RFC 2616 as reference. Please bear in mind that such document is no longer relevant nowadays and has been replaced with the following documents:

  • RFC 7230: Message Syntax and Routing
  • RFC 7231: Semantics and Content
  • RFC 7232: Conditional Requests
  • RFC 7233: Range Requests
  • RFC 7234: Caching
  • RFC 7235: Authentication

根据 RFC 7231 ,HTTP日期必须以GMT表示.因此,用UTC偏移量表示日期似乎无效.

According to the RFC 7231, HTTP dates must be expressed in GMT. So expressing dates with offsets from UTC don't seem to be valid valid.

查看如何定义 Expires 标头在 RFC 7234 :

5.3.过期

Expires 标头字段提供日期/时间,之后该日期/时间将被认为是过期的响应.[...]

The Expires header field gives the date/time after which the response is considered stale. [...]

Expires 值是例如

Expires: Thu, 01 Dec 1994 16:00:00 GMT

现在从 RFC 7231 中看到以下引用:

Now see the following quote from the RFC 7231:

7.1.1.1.日期/时间格式

在1995年之前,服务器通常使用三种不同的格式来传递时间戳.为了与旧的实现兼容,此处全部定义了这三个.首选格式是Internet邮件格式[RFC5322]使用的日期和时间规范的固定长度和单区域子集.

Prior to 1995, there were three different formats commonly used by servers to communicate timestamps. For compatibility with old implementations, all three are defined here. The preferred format is a fixed-length and single-zone subset of the date and time specification used by the Internet Message Format [RFC5322].

HTTP-date    = IMF-fixdate / obs-date

首选格式的示例是

Sun, 06 Nov 1994 08:49:37 GMT    ; IMF-fixdate

两种过时的格式的示例是

Examples of the two obsolete formats are

Sunday, 06-Nov-94 08:49:37 GMT   ; obsolete RFC 850 format
Sun Nov  6 08:49:37 1994         ; ANSI C's asctime() format

解析HTTP标头字段中的时间戳值的接收者必须接受所有三种 HTTP-date 格式.当发送方生成的标头字段包含一个或多个定义为 HTTP-date 的时间戳时,发送方必须以 IMF-fixdate 格式生成这些时间戳.

A recipient that parses a timestamp value in an HTTP header field MUST accept all three HTTP-date formats. When a sender generates a header field that contains one or more timestamps defined as HTTP-date, the sender MUST generate those timestamps in the IMF-fixdate format.

HTTP日期值将时间表示为协调世界时(UTC)的实例.前两种格式使用格林威治标准时间(格林威治标准时间)的三字母缩写表示UTC,格林威治标准时间是UTC名称的前身;假定 asctime 格式的值采用UTC.[...]

An HTTP-date value represents time as an instance of Coordinated Universal Time (UTC). The first two formats indicate UTC by the three-letter abbreviation for Greenwich Mean Time, GMT, a predecessor of the UTC name; values in the asctime format are assumed to be in UTC. [...]

这篇关于什么是有效的RFC1123日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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