2

Hello I encountered strange behavior with javascript date. I show in this example:

var date = new Date(2017, 07, 22);
console.log(date); //22. 8. 2017
console.log(date.toLocaleDateString()) //Tue Aug 22 2017 00:00:00 GMT+0200

Why is month always increment? Is normal behavior or its my problem? Thanks

Colin
  • 1,112
  • 1
  • 16
  • 27
bluray
  • 1,875
  • 5
  • 36
  • 68
  • 1
    It's not your problem:month Integer value representing the month, beginning with 0 for January to 11 for December. – huan feng Jul 27 '17 at 06:03
  • 1
    Possible duplicate of [Javascript Date.UTC() function is off by a month?](https://stackoverflow.com/questions/1507619/javascript-date-utc-function-is-off-by-a-month) – t.niese Jul 27 '17 at 06:04
  • or [javascript is creating date wrong month](https://stackoverflow.com/questions/12254333/javascript-is-creating-date-wrong-month) – t.niese Jul 27 '17 at 06:05

3 Answers3

4

Javascript Date's month starts from 0. So 7 is actually 8th Month which is August.

month

Integer value representing the month, beginning with 0 for January to 11 for December.

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

In the JavaScript Date() object, the the month is an integer, starting at 0.

  • 0 = January
  • 1 = February
  • 2 = March

and so on.

Chava Geldzahler
  • 3,605
  • 1
  • 18
  • 32
0

Javascript date month starts form zero index only ie jan is 0 and december is 11enter image description here

yasarui
  • 6,209
  • 8
  • 41
  • 75