Date.parse return type

Lars T Hansen lth at
Sat Jul 28 11:21:19 PDT 2007

On 7/28/07, doekman at <doekman at> wrote:
> On 7/23/07, Brendan Eich <brendan at> wrote:
> > On Jul 23, 2007, at 10:23 AM, doekman at wrote:
> > > In the public Date/time proposal, the Date.parse static method
> > > returns a Date. This is a bit odd, because the current javascript
> > > Date.parse method returns a number (nr. of ms since epoch). Is this
> > > by design?
> >
> > That's a mistake, which Lars noticed and corrected recently.
> OK, that's clear. But does Date.parse("2007-07-28") raise a
> SyntaxError, or does it return NaN?

No SyntaxError is ever thrown.  We've decided that was a bug that
crept into the proposal.

What Date.parse returns for that string is implementation dependent.
Date.parse is only required to correctly parse two classes of strings:
those produced by Date.prototype.toString (this is the only
requirement of ES3), and strings conforming to the ISO date syntax
profile used by ECMAScript 4.  A string of the latter class always
contains the letter 'T' even if there is no time in the string, only a

In practice implementations use all sorts of heuristics for parsing
dates and it's exceedingly likely that most implementations will
understand your string as 28 July 2007, ie, in answer to your
question, "neither".

We've opted not to specify that they *must* understand it in that way,
though.  It is possible that this particular case should be brought in
under the ISO syntax umbrella, but beyond that it's a slippery slope.
We don't really feel that we should define Date.parse much more
tightly than we do, for backwards compatibility reasons.


More information about the Es4-discuss mailing list