Reputation: 1963
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
Reputation: 3730
In the JavaScript Date()
object, the the month is an integer, starting at 0
.
0
= January1
= February2
= Marchand so on.
Upvotes: 1
Reputation: 6573
Javascript date month starts form zero index only ie jan is 0 and december is 11
Upvotes: 0
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