I know this issue and there is an issue also on GitHub as well but is there any logical reason for why the months in moment js starting from index 0?
Asked
Active
Viewed 188 times
-1
-
3Does this answer your question? [why is the javascript date month index 0-based](https://stackoverflow.com/questions/43828883/why-is-the-javascript-date-month-index-0-based) – Janar Oct 13 '20 at 10:15
-
Probably because the JS Date function also does this. https://stackoverflow.com/questions/2552483/why-does-the-month-argument-range-from-0-to-11-in-javascripts-date-constructor – evolutionxbox Oct 13 '20 at 10:15
-
It is defined in the [ECMAScript Language Specification](https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.4) – Reyno Oct 13 '20 at 10:16
-
But then days also should have this logic right? – Audi Oct 13 '20 at 10:18
-
@Singh no? Why would they. Having zero based months has a *long* history from at least back in C. Probably from before. It makes it easier to make something like (in JS) `monthNames = ["January", "February", "March", /* etc */]; monthNames[date.getMonth()]` to turn them to words. Same thing with week days. Otherwise, you need to either make an empty slot in the array (more memory) or do some more arithmetic with the month number (more CPU). Not relevant nowadays but it's an artefact from the past. Same thing can be observed with week days. There is no reason to need zero based month days. – VLAZ Oct 13 '20 at 10:23
1 Answers
0
0-based indexing of the months is a feature that Moment.js inherits from Javascript.

Raqha
- 754
- 4
- 17