I’m curious what would be the best practice to extend the Date constructor.
The problem I’m facing is, that the Internet Explorer (< 7+8) can’t parse a date like
new Date('2010-05-11');
I have to admit that this is not a standard method to parse, anyways FireFox and Chrome perform well on that kind of date string.
Now I’m wondering, should I just split/parse/rebuild the string before calling new Date() or is there a more elegant solution ?
update
I would highly prefer a native js method to accomplish that. If there isn’t a way
to somehow add a custom parsing I’ll just transform the datestring.
I think it almost always pays-off to use a library for date parsing rather than depending on the browser’s native parsing functionality.
Leaving all the fluff they bring, the least minimum that your application should have is being able to parse simple dates such as yours (yyyy-mm-dd) in a consistent manner across all browsers.
If the browsers can’t guarantee that, then there’s no point in manipulating the date string to a format that appeases all browsers. If the source string itself is in a non-standard format, such as
2010-06-08-12:29:53(note the third dash) that I recently came across on this feed, then it may make sense to standardize that, and after that you come back to the same problem – parsing natively (which IMO is a bad idea) or using a library.