How does the Date object work in JavaScript?
A date in JavaScript is really just one number. That number is the number of milliseconds since the epoch, and the epoch is midnight on the first of January 1970 in UTC. Everything else you see about a date, such as the year, the month, and the day, is a view over that single number. That is why you can add and subtract dates with plain arithmetic.
The constructor accepts several kinds of value. A string gets parsed, a number is treated as a timestamp, and no argument at all means the current moment. There are also static methods such as Date.now(), which gives the current timestamp, and Date.parse(), which turns a string into a timestamp.
Once you have a date, you read it with getter methods. The local versions, such as getFullYear(), getMonth(), getDate(), and getHours(), use the time zone of the computer. The UTC versions, such as getUTCFullYear(), use UTC instead. And toISOString() always gives a UTC string in one fixed format, which is the one you want when you store a date or send it to an API.
Two details surprise people. Month indexes start at zero, so March is the number two, while the day of the month starts at one, so the first of the month is the number one. There is also an old quirk where a two-digit year between zero and ninety is read as a year in the nineteen hundreds, and that is why setFullYear() always wants the full four-digit year.