Why there is need to add 1 to the month for this date conversion?
I have this date variable in javascript $scope.dt and the contents is Tue Jul 08 2014 00:00:00 GMT+0800 (Malay Peninsula Standard Time) . I want to convert it to return a string that is 2014-7-8 (YYYY-MM-DD). Below is the function I wrote; function convertDate_YYYYMMDD(d) { var curr_date = d.getDate(); var curr_month = d.getMonth()+1; //why need to add one? var curr_year = d.getFullYear(); return (curr_year + "-" + curr_month + "-" + curr_date ); } It works fine. What I don't understand is why do I need to add 1 to get the correct curr_month ? If I do not do this, the month will always be off