-4

when i wanna to extract a Month value i got an incorrect value :

date2 =  new Date('Mon Dec 22 2014 00:00:00 GMT+0000 (Maroc)')
date2.getMonth() // --> i got 11 !!

i can increase the value by one but is not the best the solution

Any help please

2

2 Answers 2

1

The getMonth() function starts at zero. Therefore, January will return zero and December will return 11.

You can read more about the date object and the getMonth function here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth

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

Comments

1

The getMonth() return value is zero-based.

Quoting the docs

The value returned by getMonth() is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.