-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
  • 31,517
  • 8
  • 49
  • 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
  • 16,287
  • 34
  • 113
  • 221
1

Month index starts from Jan.

0 - Jan 1 - Feb..

and so on.

Hari Chaudhary
  • 630
  • 1
  • 7
  • 20
1

If you read the docs.

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

Zee
  • 8,420
  • 5
  • 36
  • 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

Ioannis Loukeris
  • 300
  • 2
  • 10