today1 = new Date(); today2 = Date.parse('2008-28-10');
To compare the time (millisecond) values of these I have to do the following, because today2 is just a number.
if (today1.getTime() == today2)
Why is this?
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.
To answer the question in the title: Because they decided so when creating the JavaScript language. Probably because Java’s
java.util.Dateparse function was doing the same thing, and they wanted to mimic its behavior to make the language feel more familiar.To answer the question in the text… Use this construct to get two date objects:
EDIT: A simple
also works.
Note: Old Internet Explorer versions (anything before 9) does not understand dashes in the date string. It works with slashes, though:
Slashes seem to be universally understood by browsers both old and new.