Why is my JavaScript Date showing the wrong month? #49
Answered
by
Kevinchamplin
Kevinchamplin
asked this question in
Q&A
-
|
Why is my JavaScript Date showing the wrong month? |
Beta Was this translation helpful? Give feedback.
Answered by
Kevinchamplin
Jun 13, 2026
Replies: 1 comment
-
|
The Date month argument and getMonth() are 0-indexed: January is 0 and December is 11. So |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kevinchamplin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Date month argument and getMonth() are 0-indexed: January is 0 and December is 11. So
new Date(2026, 5, 1)is June, not May, and getMonth() returns 5 for June. Days of the month (and getDate) are 1-indexed, which makes the inconsistency easy to trip over — add 1 when displaying, or use a date library / Intl.DateTimeFormat.