哪些日期格式符合IETF标准的RFC 2822时间戳? [英] Which date formats are IETF-compliant RFC 2822 timestamps?

查看:5546
本文介绍了哪些日期格式符合IETF标准的RFC 2822时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


[2位数字] / [2位数月] / [4位数年] [2位数小时(24模式) ]:[2位数分钟]


例如, 16/02/2013 21:00



但如果我执行新日期('16 / 02/2013 21:00')。toString(),它给了'Wed Apr 02 2014 21:00:00 GMT + 0200(Hora de verano romance)'



我猜这是因为我的日期不遵循IETF RFC 2822日期和时间规范。然后,我应该转换我的字符串,我想将其转换为最相似的兼容格式(因为它应该更容易转换)。但 http://tools.ietf.org/html/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());

//指定Z,表示UTC时间。
document.writeln((new Date(2010-06-09T15:20:00Z))toutCString());

//指定-07:00偏移量,相当于太平洋夏令时间。
document.writeln((new Date(2010-06-09T15:20:00-07:00))toGMTString());

//指定非ISO长日期。
document.writeln((new Date(2010年6月9日))toutCString());

//指定非ISO长日期。
document.writeln((new Date(2010 June 9))。toUTCString());

//指定非ISO短日期和时间。
document.writeln((new Date(6/9/2010 3:20 pm))toutCString());

//输出:
// 2010年1月1日星期五00:00:00 UTC
//星期二,2010年6月1日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
// 2010年6月9日,星期三07:00:00 UTC
// 2010年6月9日,星期三07:00:00 UTC
// Wed,9 Jun 2010 22:20:00 UTC



Gotchas



有一个跨浏览器不一致


I need to parse dates in JavaScript. The format is

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

For example, 16/02/2013 21:00

But if I do new Date('16/02/2013 21:00').toString(), it gives 'Wed Apr 02 2014 21:00:00 GMT+0200 (Hora de verano romance)'.

I guess that's because my dates don't follow IETF RFC 2822 Date and Time Specification. Then, I should convert my string, and I want to convert it to the most similar compliant format (because it should be easier to convert). But http://tools.ietf.org/html/rfc2822#page-14 is hard to understand, so I don't know which is the most similar format.

Is there a list with examples of the allowed formats?

解决方案

MSDN has several examples of valid date formats:

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

Gotchas

There's a matrix of cross-browser inconsistencies as well.

这篇关于哪些日期格式符合IETF标准的RFC 2822时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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