23
dayo
8y

var date = new Date();
var month = date.getMonth();
console.log(month); // 2

who thought it would be a good idea to start the months of at 0 rather then 1

Comments
  • 7
    It is the number of months since January, in the range 0 to 11. Fits into an array of months nicely :D
  • 6
    We are devs. We start counting at 0.
  • 0
    all the smalltalk ^_^
  • 1
    No way manπŸ˜•πŸ˜•
  • 1
    @OS55 I don't think he sees it as a problem just he is being anal about giving the numbers a different meaning.
  • 3
    The dumb thing with dates is that month starts at 0 but days start at 1 and you never have to +1 on years

    So month are really the odd one out

    But really, that one of the lesser evils of dates ;)
  • 0
    Always remember in the memory indexing starts with 0
  • 1
    I immediately ran to my computer to fix this in the javascript app I was working on. I didn't even think js would work this way
  • 0
    This is how localtime is coded on Linux
  • 1
    @ocab19 glad I could help, is just so weird how the Date function is so inconsistent with some starting at 1 and others at 0. I could at least live with it if it all made sense
  • 0
    @dayo you will survive, use the stress ball
Add Comment