-4

I am using - new Date(2014, 5, 2). But it is not showing the proper date.

When i do console.log(new Date(2014, 5, 2)); on the console it returns - Mon Jun 02 2014 00:00:00 GMT+0530 (India Standard Time). Why June? Should not it be May?

Sougata Bose
  • 30,871
  • 8
  • 44
  • 87

5 Answers5

2

The month index starts from 0, not from 1... Then 0 is January...

See: http://www.w3schools.com/jsref/jsref_getmonth.asp

Snake Eyes
  • 15,519
  • 32
  • 105
  • 203
1

Month index starts from Jan.

0 - Jan 1 - Feb..

and so on.

Hari Chaudhary
  • 580
  • 1
  • 6
  • 19
1

If you read the docs.

JavaScript counts months from 0 to 11. January is 0. December is 11.

Zee
  • 8,300
  • 5
  • 34
  • 58
0

No June is correct, May was last month. Check out w3schools example of the format you're trying to use: http://www.w3schools.com/js/js_dates.asp

0

Months are zero based. i.e. January is 0 February is 1 etc.

W3Schools tutorial