What date format will javascript recognize?

I know when creating an object Datein javascript with a parameter dateString, the string should be something that can recognize parse().

What date format can it parserecognize?

For instance:

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

works in Chrome and Internet Explorer, but doesn’t work on iPhone (returned January 1, 1970).

I can not find the official documentation on the method .parse()or constructor about what the parameter should be.

The format yyyy-mm-ddThh:nn:ssdoes not work. What is a valid format string?

+5
source share
2 answers

MDCDate.parse() documentation states (cited):

IETF (RFC 1123 5.2.14 ) :
"Mon, 25 Dec 1995 13:30:00 GMT".


OP Edit:

.NET datetime:

/*
 * 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

: r ( RFC1123) "GMT", GMT ​​( ). .ToUniversalTime(), GMT.

+11

, Date toJSON, . , toIOSString.

: YYYY-MM-DDTHH: mm: ss.sssZ

. UTC, "Z".

var d = new Date();
console.log(d.toJSON());
console.log(d.toJSON() === d.toISOString());
console.log(Date.parse(d.toJSON()) === Date.parse(d.toISOString()));

, , ; UTC.

:

Date.prototype.toJSON()

Date.prototype.toISOString()

0

All Articles