javascript的解析识别什么字符串日期格式? [英] What string date format will javascript's parse recognize?

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

问题描述

我知道在javascript中使用 dateString 参数构建 Date 对象时,字符串必须是 parse()可以识别。



什么日期格式可以解析识别?



例如:

  var postDate = new Date (2011-03-08T23:52:38); 

适用于Chrome和Internet Explorer,但在iPhone上失败(返回1970年1月1日) / p>

我无法在 .parse()方法或构造函数中找到有关参数应该是什么的正式文档



格式 yyyy-mm-ddThh:nn:ss 不起作用。 允许的格式字符串

解决方案

MDC文档 Date.parse() 状态(引用)


它接受 IETF标准 RFC
1123
第5.2.14节和其他地方)
日期语法:
1995年12月25日星期一13:30:00 GMT







OP编辑:



创建此datetime字符串的.NET语法:

  / * 
* r(RFC1123Pattern)
* ddd,dd MMM yyyy HH':​​'mm':'ss 'GMT'
*星期一,2009年6月15日20:45:30 GMT
* /
dateTime.ToUniversalTime()。ToString(r,CultureInfo.InvariantCulture); //r= RFC1123Pattern




编辑: strong> r (RFC1123模式)始终追加GMT,即使时间不是GMT(本地)。您需要首先调用 .ToUniversalTime(),以实现实际的格式。


< blockquote>

i know when constructing a Date object in javascript with a dateString parameter, the string must be something that parse() can recognize.

What date format can parse recognize?

For example:

var postDate = new Date("2011-03-08T23:52:38");

works in Chrome and Internet Explorer, but fails on an iPhone (returns Jan 1, 1970).

i cannot find any formal documentation on the .parse() method, or the constructor, about what the parameter should be.

The format yyyy-mm-ddThh:nn:ss doesn't work. What is the allowed format string?

解决方案

The MDC documentation of Date.parse() states (quoting) :

It accepts the IETF standard (RFC 1123 Section 5.2.14 and elsewhere) date syntax:
"Mon, 25 Dec 1995 13:30:00 GMT".


OP Edit:

.NET syntax to create this datetime string:

/*
 * r (RFC1123Pattern)
 *      ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
 *      Mon, 15 Jun 2009 20:45:30 GMT
 */
dateTime.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture); //"r" = RFC1123Pattern

Edit: The r (RFC1123 pattern) always appends "GMT", even though the time isn't GMT (it's local). You need to call .ToUniversalTime() first, in order to have the time actually be GMT.

这篇关于javascript的解析识别什么字符串日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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