I'm trying to understand how javascript's Date
api acts when parsing the date and I cant justify the way javascript parse same dates but different formats into different dates.
const date1 = new Date('2020-05-13');
const date2 = new Date('2020-12-28');
const date1Reversed = new Date('05-13-2020');
const date2Reversed = new Date('05-28-2020');
console.group('Date Format: YYYY-MM-DD')
console.log(date1);
console.log(date2);
console.groupEnd();
console.group('Date Format: MM-DD-YYYY')
console.log(date1Reversed);
console.log(date2Reversed);
console.groupEnd();
Above code gives below output
Date Format: YYYY-MM-DD
2020-05-13T00:00:00.000Z
2020-12-28T00:00:00.000Z
Date Format: MM-DD-YYYY
2020-05-12T21:00:00.000Z
2020-05-27T21:00:00.000Z
Dates are identical but the mm-dd-yyyy
date parsed into GMT-3, what is the logic behind this ?