0
    var date1 = new Date('1900-01-01');
    console.log(date1);

Yields: "Mon Jan 01 1900 01:00:00 GMT+0100 (W. Europe Standard Time)"

    var date2 = new Date(1900,1,1);
    console.log(date2);

Yields: "Thu Feb 01 1900 00:00:00 GMT+0100 (W. Europe Standard Time)"

Fiddle

But I don't understand why!

crosstalk
  • 31
  • 4

1 Answers1

1

You can see the month difference since when you pass individual components (year, month, day, etc) to the Date object constructor, you have to consider that month parameter should start with 0:

console.log( new Date('1900-01-01').getMonth() );  // 0

Other than Jan/Feb there shouldn't be any differences in dates.

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

VisioN
  • 143,310
  • 32
  • 282
  • 281
  • @RobbyCornelissen It shouldn't display any hour difference, just month difference. – VisioN Jul 12 '16 at 11:15
  • Agreed. It shouldn't. But that's what's in the question... Typo maybe? – Robby Cornelissen Jul 12 '16 at 11:16
  • @RobbyCornelissen I tend to think that this is a typo. – VisioN Jul 12 '16 at 11:23
  • @crosstalk Fiddle will display exactly what *your* browser will display. In my case the time is the same: https://i.gyazo.com/d949455b043ffc7f0929d278aeb618ef.png. – VisioN Jul 12 '16 at 11:35
  • Should've been more clear - It's only the jan/feb thing that confuses me - but you're saying that is supposed to be like that? – crosstalk Jul 12 '16 at 11:39
  • Yeah, Jan/Feb thing is supposed to be like that because of month numbering in JavaScript. However, I don't know why you have different time. It may be something related to your locale, although not sure. – VisioN Jul 12 '16 at 11:41
  • Ah, ok - so months starts on 0 and days on 1? But why? :-) Agree with the time explanation though. – crosstalk Jul 12 '16 at 11:43
  • @crosstalk Yes, months start with 0. Here is one brief discussion about that: http://stackoverflow.com/q/2552483/1249581 `:)` – VisioN Jul 12 '16 at 11:53
  • @VisioN: Haha! Thanks for the link :-) – crosstalk Jul 12 '16 at 11:59