let a = new Date()
a.setDate(1) <--- this set date to the first date of this month.
However
let b = new Date ('2020-02-15')
b.setDate(1)
b.toISOString() -> returns'2020-02-02T00:00:00.000Z'
What’s going on?
>Solution :
Timezones. You’re initializing date a with the current time, and b at midnight local time, which (depending on the time of day where you are) can be a different day when represented in UTC.
let a = new Date()
a.setDate(1);
let b = new Date('2022-02-14');
b.setDate(1);
console.log("UTC:")
console.log(a.toISOString());
console.log(b.toISOString());
console.log('Local timezone:')
console.log(a.toLocaleString())
console.log(b.toLocaleString())