2

Now this seems kind of odd...

I have an array like this:

a = ["2014", "03", "12", "08", "43", "51"]

which I need to convert into a DateTime object. However:

new Date(a[0], a[1], a[2], a[3], a[4], a[5]);

returns Date {Sat Apr 12 2014 08:43:51 GMT+0200 (CEST)}

Question
What happened to March?

frequent
  • 27,643
  • 59
  • 181
  • 333

3 Answers3

3

JavaScript uses 0 as January, 1 as February, so on till 11 as December. It is like array of of months from 0 to 11. Thats why it converts three as April

Programmer
  • 60
  • 1
  • 6
2

Try this

a = ["2014", "02", "12", "08", "43", "51"]

We are starting counting (only) month at zero.

Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
2

For some reason, months in Javascript date are from 0 to 11 and not from 1 to 12

Sleiman Jneidi
  • 22,907
  • 14
  • 56
  • 77