Parsing ISO-8601 format date not working in IE 9

I have a date (see dateValue variable) returned from the ajax response. Parsing that value works in chrome but not in IE 9.

Am I missing anything? Any help / suggestion is appreciated.

var dateValue = "2015-08-12T16:31:51.68";

$('#result').text(Date.parse(dateValue));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="result"></label>

Answers:

Answer

ISO-8601 date parsing was added in ES5, so not all browsers support it.

Check this github project for an implementation that might work for you.

Or you could use a library like moment.js for better cross browser capability.

var dateValue = "2015-08-12T16:31:51.68";
$('#result').text(moment(dateValue););
Answer

IE9 is in quirks mode, and you want it in standards mode.

To learn how to force standards mode, see this answer: How do I force Internet Explorer to render in Standards Mode and NOT in Quirks?

When in quirks mode, javascript only works if it was supported in IE6. Date.parse was not a JS feature in IE until version 9

To check if you are in quirks mode, run this JS:

alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode.')

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.