1

I was able to parse date string in JavaScript using the following script:

var mydate = new Date(Date.parse('06/15/2012','MM/dd/yyyy'));

What really bothers me is that there is no proper documentation for the above method. MSDN, w3school and Mozilla developer sites have docs on one parameter only.

i.e., Date.parse('some date string');

What is the best JavaScript reference that has correct up to date information?

2 Answers 2

1

The method only pays attention to the first parameter. That is,

var mydate = new Date(Date.parse('06/15/2012'));

would give you the same result.

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

1 Comment

Pointy - Thanx. It worked with one parameter. I guess the post that recommended the second parameter was wrong.
1

The MDN documentation is correct.

Javascript is a dynamic, weakly typed language and it doesn't check method signatures. It just passes whatever you put into a method call to the Function object and lets it worry about it.

In this case, Date.parse ignores your second parameter.

The reason that it works is because Date.parse is designed to recognise RFC 2822 compliant dates and... parse them.

If you execute

Date.parse('06/07/2012','MM/dd/yyyy') === Date.parse('06/07/2012','dd/MM/yyyy')

in a browser console, you'll see that the second string made no difference to the parsing.

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.