4 Replies
Because timezones. If you don't give a timezone offset
new Date()
assumes midnight UTC.
For example, I am currently in GMT-5 US Central time zone:
If you do the math and add the 5-hour offset the time is exactly midnight GMTAh okay makes sense. Thank you. I noticed when I changed format to mm-dd-yyyy it gives different log.
I figured out how to get the offset number, I just cant figure out how you actually add it to the date.
Here's the spec for the date string:
https://tc39.es/ecma262/#sec-date-time-string-format
Add the +HH:MM or -HH:MM to set the time zone offset (in place of the
Z
in the string)thank you