Aaron Thomas Aaron Thomas -4 years ago 87
Javascript Question

Wrong month with moment.js?

The docs for moment.js say one way to create a moment object is by passing in an array.

However, if I do this for Jan 1, 2017 in this way, I get an unexpected result:

moment([2017,1,1]).toString()


... leads to the result of "Wed Feb 01 2017 00:00:00 GMT-0600"

Am I doing something wrong here, or is it a bug in the library?

I'm using version 2.17.1 in Firefox, and also got same results with 2.18.1 in Chrome on a different computer with a different OS.
I'm using v 2.17.1.

Answer Source

It looks like it uses the JavaScript interpretation of a month and 0-indexes the month. So 0 = January, 1 = February, etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download