-4

I am trying to use the "new Date()" function but my dates are not coming out correctly.

This date & time is correct if I use:

new Date(); //outputs Wed Jul 05 2017 13:16:31 GMT-0700 (Pacific Daylight Time)

When I try to change the date, it comes out incorrect:

new Date(2017,07,03,12,01,36); //outputs Thu Aug 03 2017 12:01:36 GMT-0700 (Pacific Daylight Time)

I'm not sure why it says "Aug" when it should be "Jul".

Thanks In Advance!

wbadart
  • 2,583
  • 1
  • 13
  • 27
626
  • 1,159
  • 2
  • 16
  • 27
  • 1
    https://stackoverflow.com/questions/43828883/why-is-the-javascript-date-month-index-0-based – wbadart Jul 05 '17 at 20:21
  • I apologize for the duplicate, I didn't see the other questions when searching my issue. Thank You – 626 Jul 08 '17 at 08:13

3 Answers3

2

month is 0-based

Date - JavaScript | MDN

new Date(2017,06,03,12,01,36) // Mon Jul 03 2017 12:01:36 GMT-0700 (PDT)

Similar questions

Miguel Mota
  • 20,135
  • 5
  • 45
  • 64
1

It is because months start from zero. So, if you want July, you have to set month to 06

Bunyamin Coskuner
  • 8,719
  • 1
  • 28
  • 48
0

The month parameter starts at 0, so if you want to put July you must write 6 instead of 7.

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date

яay0be
  • 11
  • 3