The following script returns 20 instead of 21!
var d = new Date("2010/03/21");
document.write(d.getDate());
What am I doing wrong? Is this a JavaScript bug?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
Date.parsemethod is implementation dependent (new Date(string)is equivalent toDate.parse(string)).While this format will be available on modern browsers, you cannot be 100% sure that the browser will interpret exactly your desired format.
I would recommend you to manipulate your string, and use the Date constructor with the year, month and day arguments: