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?
Using the format that is produced by Date's toJSON method will work. This is the same as the toIOSString method.
The date format is YYYY-MM-DDTHH:mm:ss.sssZ
Note: The timezone is always UTC as denoted by the suffix "Z".
You may find that the date shown isn't the same as on your clock; remember the timezone is UTC.
References:
Date.prototype.toJSON()
Date.prototype.toISOString()
The MDC documentation of
Date.parse()
states (quoting) :OP Edit:
.NET syntax to create this datetime string: