Firstly, when I say other browsers I really only mean Firefox because that’s all I tested in.
Internet Explorer can parse a date followed by a single character as a proper date. Whereas Firefox behaves as I’d expect.
For example…
var dateString = new Date("1/1/2010f");
alert(dateString);
In IE it will alert…
Thu Dec 31 21:00:00 UTC-0900 2009
Whereas in FF is will spit out…
“Invalid Date”
I first noticed this using the jquery validation plug in.
http://docs.jquery.com/Plugins/Validation/Methods/date
It seems like it just subtracts some amount of hours off the actual date in IE when a character is appended. I’ve tested in IE6 and IE8.
Am I missing something?
It is implementation dependent.
When Date as a “constructor” is passed a string object, it tries to build a date with its parse method (
Date.parse).That method shall parse strings returned by
Date.toString()andDate.toUTCString(), which both return formats varying with the implementation. And this is how the ECMAScript standard says it should be.I remember reading this in “the Rhino book” (Tommy Flanagan’s great javascript book).
In practice, it might very well turn out everyone except IE does it the same way, but I haven’t tested thoroughly.
Also, it is a bit much if IE tries to parse whatever one throws at it and produces a Date object out of ascii soup.