3 ms·
Zero-based months is awkward when printing as a number, but convenient when indexing an array: const MONTHS = ["Jan", "Feb", "Mar", ..., "Dec"]; consol
by nayuki 4y ago
Zero-based months is awkward when printing as a number, but convenient when indexing an array:
const MONTHS = ["Jan", "Feb", "Mar", ..., "Dec"];
console.log(MONTHS[d.getMonth()]);
- stingraycharles 4y agoIs subtracting 1 really that much an inconvenience, given how awkward they are?
- pvorb 4y agoYes, that was always my theory for why months are 0-based. Back in the days of early Unix, this might have had a tiny performance benefit that was enough for them to choose that implementation.
- zzo38computer 4y agoI think that it should be unnecessary. The address of the array could be adjusted at compile-time so that one-based index numbers will be possible.
- pvorb 4y agoI think people are overestimating the features of compilers. Today's compilers might struggle with that. 70's compilers even more.
- deleted 4y ago[deleted]