Wrong date

Maybe I’m tired now, but does someone know why it is occurring? See:

constructor() {
  let strDt = '2018-10-31';
  let dt = new Date(strDt);

  console.log('strDt = ' + strDt, 'dt = ' + dt);
}

The result is:

strDt = 2018-10-31
dt = Tue Oct 30 2018 21:00:00 GMT-0300 (Brasilia Standard Time)

Why? Since I know only months in JavaScript starts in 0 and end in 11. The days too? I’ve never paid attention to this.

** here and now: 2018-10-03 14:09:00

Because JavaScript is badly designed in general, and Date is one of the wonkiest parts. I recommend using ISO8601 strings and date-fns to wrangle them.

The answer to your specific question, however, lies in here:

Support for ISO 8601 formats differs in that date-only strings (e.g. “1970-01-01”) are treated as UTC, not local.

So your constructor gets midnight zulu, and since your local time zone is three hours behind, you get 2100 the night before the date you expected.