Safari Screws Up Dates!

I just spent an annoying hour dealing with the fact that Safari's Javascript engine does not correctly parse standard (ECMA-262) date strings.

Here is a valid date string (coming from my database server):


Creating a date object is simple:

dateObj=new Date('2012-01-31T00:00:00');

and this works great in every browser except Safari. Safari tells you you have an "invalid date".

After screwing around way too much, I found that this works:

dateObj=new Date('2012/01/31');

And so, I changed my code to:

dateString='2012-01-31T00:00:00'.replace(/t.*$/, '').replace(/-/g, '/'); //ie, '2012/01/31'
dateObj=new Date(dateString);

I'm guessing that, if you needed the time, you'd have to split that off the string and use:


but I don't have time, or need, to figure that out now.