So when you do a 2-digit day, you get the timezone-adjusted timestamp from UTC. You’re somewhere west of the prime meridian, so you got a negative offset, as i do:
> new Date("2022-01-23")
< Sat Jan 22 2022 19:00:00 GMT-0500 (Eastern Standard Time)
Note that it gave me a timestamp that is 5 hours back - making it SATURDAY THE 22nd, not Sunday the 23rd.
If i put the 9th in as a 2-digit day, I get the same:
> new Date("2022-01-09");
< Sat Jan 08 2022 19:00:00 GMT-0500 (Eastern Standard Time)
If however, I put in a single-digit day, the Date constructor has to parse it differently (because standard format is a 2 digit day: YYYY-MM-DD), and so I get a Midnight Local timestamp, as opposed to a Midnight-UTC timestamp:
> new Date("2022-01-9");
< Sun Jan 09 2022 00:00:00 GMT-0500 (Eastern Standard Time)
And now it’s Sunday.
You can force a two-digit day to return a Local-Midnight timestamp by adding “00:00:00” at the end of the date:
> new Date("2022-01-23 00:00:00")
< Sun Jan 23 2022 00:00:00 GMT-0500 (Eastern Standard Time)