Mistake | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Mistake

In third example “//Sat Jun 11 1988 11:42:00 var d3 = new Date(88,5,11,11,42,0,0);” I think the month should be May instead of June, or am I wrong?

8th Apr 2019, 7:24 PM
Azhar Ul Islam 🇵🇰
Azhar Ul Islam 🇵🇰 - avatar
5 Answers
+ 2
The Date object in JavaScript uses 0 through 11 for months. This means 0 represents January and 11 represents December. Its a little confusing, but thats how its implemented. Hope that clarified things.
8th Apr 2019, 7:50 PM
Victor Andersson
Victor Andersson - avatar
0
Again, what are you referring to? https://www.sololearn.com/discuss/1316935/?ref=app
8th Apr 2019, 7:37 PM
Anna
Anna - avatar
0
i got it, I am mistaken, as javascript uses strange numbers for months in the Date objects. number 5 actually (although strangely) represents June instead of May.
8th Apr 2019, 7:41 PM
Azhar Ul Islam 🇵🇰
Azhar Ul Islam 🇵🇰 - avatar
0
yes, correct, still it is confusing for me that date starts at 1, but month starts at 0
9th Apr 2019, 4:41 AM
Azhar Ul Islam 🇵🇰
Azhar Ul Islam 🇵🇰 - avatar
0
I agree, but mostly I just think of it as indexes in arrays. If you were to add 12 months to an array your index would be from 0 to 11 by default. A lot of other languages don’t do it this way and prefer the more life like 1 through 12.
9th Apr 2019, 4:59 AM
Victor Andersson
Victor Andersson - avatar