I’m confused but in javascript:
> new Date('2012-1-15') - new Date('2012-01-15')
21600000
Why is that? (21600000 / 1000 / 3600 == 6 hours)
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 format
yyyy-mm-dd(2012-01-15) is parsed as being a UTC date whileyyyy-m-dd(2012-1-15) is parsed as a local date. This is shown if you use.toStringon each.Note that I am in California, hence the Pacific Standard Time. If you are in a different time zone you will get different results.
When JavaScript parses dates it tries formats used in more areas (such as UTC) first before it tries localized date formats. The last part of the UTC date format is a timezone offset from GMT which is assumed to be 0 when it is missing (as it is in this example). To get the same date you would need the full UTC timestamp: 2012-01-15T00:00:00-08:00.