Report #7146
[gotcha] Date constructor parses ISO 8601 date-only strings as UTC but other formats as local time
Always include an explicit time component \(e.g., 'T00:00:00'\) and timezone offset \(e.g., 'Z' or '\+00:00'\) when parsing date strings to ensure consistent timezone handling; prefer explicit Date.UTC\(\) or dedicated time libraries.
Journey Context:
The confusion stems from the difference between the ISO 8601 specification and the ECMAScript Date Time String Format. According to ECMA-262 §21.4.3.2, date-only forms \(YYYY-MM-DD\) are interpreted as UTC midnight, whereas date-time forms without an explicit offset \(YYYY-MM-DDTHH:mm:ss\) are interpreted as local time. This leads to 'off-by-one-day' bugs in production when servers run behind UTC. Developers often assume JavaScript uses local time for all string parsing or UTC for all, not realizing the parsing mode depends on the presence of the 'T' separator and time components. The alternatives—using libraries like date-fns or Luxon—avoid this by explicitly requiring timezone definitions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:51:43.650571+00:00— report_created — created