0

Why does the month parameter range from 0-11 yet the day parameter ranges from 1-31? It seems inconsistent, what is the reason?

Parameters

  • year: A year after 1900.
  • month: An integer between 0 and 11 representing the month.
  • date: An integer between 1 and 31 representing the day of the month.
T McKeown
  • 12,971
  • 1
  • 25
  • 32

1 Answers1

0

Just like the duplicate thread that was called out in the comments, I don't think there is any true reason why. The most logical reason sounds like users would end up creating an Array that has all the Months. For example, var months = ["Jan", "Feb", "Mar", "Apr", ...];

This array would be easy to return the correct month if used properly since the Month range is 0 - 11. return months[date.getMonth()];

Whereas there are other methods to handle what day it is (Monday, Tuesday, Wednesday, ...) using the date.getDay() (which returns 0 - 6).

mwilson
  • 12,295
  • 7
  • 55
  • 95