bluray
bluray

Reputation: 1963

Javascript date - month always increment

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

Upvotes: 2

Views: 439

Answers (3)

Chava Geldzahler
Chava Geldzahler

Reputation: 3730

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

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

and so on.

Upvotes: 1

yasarui
yasarui

Reputation: 6573

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

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 122026

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.

Upvotes: 4

Related Questions