javascript - 哪些日期格式是符合 IETF 标准的 RFC 2822 时间戳?

标签 javascript date datetime rfc rfc2822

我需要在 JavaScript 中解析日期。格式是

[2 digits day]/[2 digits month]/[4 digits year] [2 digits hour (24 mode)]:[2 digits minute]

例如,16/02/2013 21:00

但是如果我执行 new Date('16/02/2013 21:00').toString(),它会给出 'Wed Apr 02 2014 21:00:00 GMT+ 0200(Hora de verano 浪漫)'

我想那是因为我的日期不符合 IETF RFC 2822 日期和时间规范。然后,我应该转换我的字符串,我想将它转换为最相似的兼容格式(因为它应该更容易转换)。但是https://www.rfc-editor.org/rfc/rfc2822#page-14很难理解,所以我不知道哪种格式最相似。

是否有包含允许格式示例的列表?

最佳答案

MSDN有几个有效日期格式的例子:

document.writeln((new Date("2010")).toUTCString()); 

document.writeln((new Date("2010-06")).toUTCString());

document.writeln((new Date("2010-06-09")).toUTCString());

 // Specifies Z, which indicates UTC time.
document.writeln((new Date("2010-06-09T15:20:00Z")).toUTCString());

 // Specifies -07:00 offset, which is equivalent to Pacific Daylight time.
document.writeln((new Date("2010-06-09T15:20:00-07:00")).toGMTString());

// Specifies a non-ISO Long date.
document.writeln((new Date("June 9, 2010")).toUTCString());

// Specifies a non-ISO Long date.
document.writeln((new Date("2010 June 9")).toUTCString());

// Specifies a non-ISO Short date and time.
document.writeln((new Date("6/9/2010 3:20 pm")).toUTCString());

// Output:
// Fri, 1 Jan 2010 00:00:00 UTC
// Tue, 1 Jun 2010 00:00:00 UTC
// Wed, 9 Jun 2010 00:00:00 UTC
// Wed, 9 Jun 2010 15:20:00 UTC
// Wed, 9 Jun 2010 22:20:00 UTC
// Wed, 9 Jun 2010 07:00:00 UTC
// Wed, 9 Jun 2010 07:00:00 UTC
// Wed, 9 Jun 2010 22:20:00 UTC

陷阱

有一个矩阵 cross-browser inconsistencies

引用资料

关于javascript - 哪些日期格式是符合 IETF 标准的 RFC 2822 时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14914739/

相关文章:

javascript - R 中 javascript reduce 的等价物

javascript - 按日期 DD/MM/YY 格式对 JS 数组进行排序

c# - 为什么我们使用时间跨度从另一个日期减去一个日期时得到负值

java - 如何使用 JodaTime 表示转换回标准时间期间的 "repeated"小时?

datetime - jq 解析日期到时间戳

javascript - 在 x 时间后一个接一个地运行 JavaScript 函数

javascript - 使用 ng-repeat 重新加载时未设置选择项目的内容

javascript - ajax 调用后使用 php 变量

java - 如何在 Java 中将 "HH:MM"格式字符串转换为时间戳?

PHP日期偏移量