0

In javascript, I can not do new Date("10Apr14") in IE, it will give back invalid Date, but the same command works fine in chrome.

Anyone knows how to make it work for all browers?

Thanks

2

1 Answer 1

1

The problem is you are using a 2 digit year (see year in RFC 2822). You should use:

new Date('10Apr2014'); // April 10, 2014

Or better yet, don't pass a string into the Date constructor because that can be error prone and is generally less common. It is much better to use it like this:

new Date(2014, 3, 10); // April 10, 2014

See this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.