我知道在使用 dateString
参数在 JavaScript 中构造 Date
对象时,字符串必须是 parse()
可以识别的字符串。
解析
可以识别什么日期格式?
例如:
var postDate = new Date("2011-03-08T23:52:38");
在 Chrome 和 Internet Explorer 中工作,但在 iPhone 上失败(1970 年 1 月 1 日返回)。
我找不到关于 .parse()
方法或构造函数的任何关于参数应该是什么的正式文档。
yyyy-mm-ddThh:nn:ss
格式无效。允许的格式字符串是什么?
最佳答案
MDC documentation of Date.parse()
声明(引用):
It accepts the IETF standard (RFC 1123 Section 5.2.14 and elsewhere) date syntax:
"Mon, 25 Dec 1995 13:30:00 GMT"
.
OP 编辑:
创建此日期时间字符串的 .NET 语法:
/*
* 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 - JavaScript 的解析将识别哪种字符串日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5418631/