-3
new Date("Tue Apr 08 2008 00:00:00 GMT+0530").getMonth() returns 3?

Why does this datetime format returns -1 month. Also can any one please tell me is this UTC timestamp or GMT or ISO. I am pretty confused. Any help is greatly appreciated.

user3205479
  • 1,443
  • 1
  • 17
  • 41
  • [Read the documentation for Date....](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth) – epascarello Sep 01 '17 at 15:33
  • @AndrewLohr looks like you're conflating W3 and W3schools, which many will take offense of. The two organizations are unrelated, and while W3schools can be a good resource for beginners, it has often been criticized for publishing incorrect data and taking too long to correct it after having been notified. – Aaron Sep 01 '17 at 15:34
  • @AndrewLohr what is this time format is called? – user3205479 Sep 01 '17 at 15:36
  • @Aaron thanks for clearing that. Where would you suggest is the best place for js documentation? – Andrew Lohr Sep 01 '17 at 15:36
  • 1
    [MDN](https://developer.mozilla.org/en-US/) is much more accurate than w3schools @AndrewLohr BTW W3Schools has nothing to do with the W3C – Liam Sep 01 '17 at 15:38
  • 2
    @AndrewLohr you can check the different ECMA specifications on [their website](https://www.ecma-international.org/publications/) if you want the formal definition, otherwise I like the [Mozilla Developper Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) for their simplified and localized documentation. – Aaron Sep 01 '17 at 15:39

3 Answers3

0

The month field is 0 indexed :

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

month

Integer value representing the month, beginning with 0 for January to 11 for December.

Community
  • 1
  • 1
Karl Reid
  • 2,147
  • 1
  • 10
  • 16
0

getMonth() is returning the right date, it's just zero indexed, so Jan = 0, Dec = 11

new Date("Tue Apr 08 2008 00:00:00 GMT+0530").getMonth()

Also, ISO formatted dates look like this:

YYYY-MM-DDTHH:mm:ss.sssZ

If the Z is present, UTC is used, otherwise you can replace the Z with +hh:mm or -hh:mm to specify an offset from UTC.

Stephen R. Smith
  • 3,310
  • 1
  • 25
  • 41
-1

Possibly because it is returning the month index from base 0.

January=0

Febuary=1

March=2

April =3

etc.

Just a guess though.

Bigbob556677
  • 1,805
  • 1
  • 13
  • 38