Report #103016
[gotcha] Why is my JavaScript Date off by one day for date-only strings like '2024-01-01'?
Treat ISO 8601 date-only strings \(YYYY-MM-DD\) as UTC midnight and date-time strings without a timezone offset as local time. For unambiguous date handling, parse explicitly with date-fns-tz, luxon, or dayjs, or construct dates with Date.UTC / explicit components. Never rely on the Date constructor for user-facing date logic.
Journey Context:
The ECMAScript Date Time String Format specifies that date-only forms are parsed as UTC, while date-time forms without an offset are parsed as local time. This means new Date\('2024-01-01'\) can produce December 31 in western timezones, whereas new Date\('2024-01-01T00:00:00'\) produces January 1 local. MDN notes this behavior is a historical spec error kept for web compatibility. Non-ISO strings are implementation-defined. Developers often 'fix' this by manually adding timezone offsets, which breaks across DST and locales. Explicit parsing or a dedicated date library is the only robust solution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:52:44.239404+00:00— report_created — created