2

I have read numerous explanation attempts why this was created like this back in the day (with both year and day index are not being 0-based). None of these explanations really made sense.

What is even more surprising to me: even in the latest ECMAScript 2018 draft, this issue still exists. see dates in ECMAScript 2018

Javascript might have just taken this from Java long time ago but I don't see why it is not being changed unless there actually is a proper reason for it.

Thanks & regards, Marcel

paulsm4
  • 114,292
  • 17
  • 138
  • 190
Marcel
  • 651
  • 1
  • 5
  • 6
  • 3
    Q: Did you celebrate the new millenium Jan 1, 2000 ... or Jan 1, 2001? – paulsm4 May 07 '17 at 07:27
  • `why it is not being changed unless there actually is a proper reason for it.` dude just assumes changing this "little" detail is like opening up the file in an editor, locate the line, backspace, backspace, save, done. Not easy bud – Trash Can May 07 '17 at 07:30
  • Paraphrased from the duplicate: _TL;DR: Because months and weekdays have names and days of the month do not._ – mplungjan May 07 '17 at 07:34
  • @paulsm4: I went with both. :-) Hey...party! – T.J. Crowder May 07 '17 at 07:39
  • Days of the week are also zero indexed (Sunday = 0) as are years. So zero indexing months makes sense. – RobG May 07 '17 at 08:27

1 Answers1

2

why is the javascript date month index 0-based

It's not surprising. The day of the week is also 0-based. In both cases, it's common to want to look up symbolic versions of them in arrays (e.g., ["January", "February", ...], ["Sunday", "Monday", ...]). Arrays are 0-based. JavaScript is by far not the only language/runtime that uses 0-based values for this.

What is even more surprising to me: even in the latest ECMAScript 2018 draft, this issue still exists.

It would be much more surprising if they changed this 22 years after the fact, blowing up millions of scripts, esp. as it's perfectly rational the way it is. They could add a new accessor that does the +1 for you, but...yeah, I wouldn't hold my breath. :-)

The only reason for 1-based versions of these is formatting. Formatting isn't handled by JavaScript at all. There is some formatting in ECMA-402: ECMAScript® 2016 Internationalization API Specification, in the form of DateTimeFormat.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875