0

I have a string consisting of '2013-04-05T00:00:00'. When I embed the below code into my js file Chakra (IE javascript engine) barfs. When I run this from the IE console it barfs. Every other browser I have tested on is fine. How can i make the below statement browser agnostic?

var targetDate = new Date('2013-04-05T00:00:00');
alert(targetDate);

EDIT
IE version 7,8 does not run

runs fine in ie 9+

EDIT#2

The reason this doesn't work is that IE 8,7 do not support ISO date times. You will either need to generate a Date object from a non ISO date time stamp.

gh9
  • 10,169
  • 10
  • 63
  • 96

1 Answers1

2

I would suggest using Date.js to fix up these Date parsing issues. This will work in IE8:

<html>
   <body>
   <script src="http://www.datejs.com/build/date.js" type="text/javascript"></script>
   <script>
      var targetDate = Date.parse('2013-04-05T00:00:00');
      alert(targetDate);
   </script>
   </body>
</html>

Note, you'll have to use the Date.parse method rather than the Date() constructor.

Fiddle

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326