0

Using Chrome and and in the console new Date(2015, 12, 20) will return the following in the Chrome console window...

Wed Jan 20 2016 00:00:00 GMT-0500 (Eastern Standard Time)

This also occurs in my javascript (js) file.

I have also tried parseInt with the same result

var month = parseInt(valueUnwrapped.getUTCMonth() + 1); //months from 1-12
var day = parseInt(valueUnwrapped.getUTCDate());
var year = parseInt(valueUnwrapped.getUTCFullYear());
var dte = new Date(year, month, day);
myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
David
  • 3,047
  • 4
  • 45
  • 79

2 Answers2

8

month value is a 0-based number, 0 being January. If it goes beyond 11, the date rolls over.

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

doogle
  • 3,376
  • 18
  • 23
  • 1
    True as it is, this defies expectation or convention. Every other language I've ever encountered uses 1-12 for a numeric month value. – Flynn1179 Dec 24 '15 at 16:53
  • No argument there. I only knew this off hand because I ran into the same problem a couple months back and thought "well that's stupidly unintuitive" – doogle Dec 24 '15 at 16:55
  • Ironically, so did the OP, judging by the first line of the code fragment. – Flynn1179 Dec 24 '15 at 16:56
0

new Date("2015, 12, 20")

Can you try this instead?

CFNinja
  • 3,571
  • 4
  • 38
  • 59