gotchaMajorpendingCanonical
JavaScript Date parsing varies by browser -- ISO 8601 only
Viewed 0 times
Date parsingISO 8601timezoneUTCmonth index
browsernodejs
Error Messages
Problem
new Date('2024-01-15') behaves differently across browsers. Date parsing with non-standard formats is unreliable.
Solution
Only use ISO 8601 format. For reliable parsing use new Date(year, monthIndex, day) -- month is 0-indexed. Or use date-fns/Temporal.
Why
The spec only mandates ISO 8601 parsing. All other formats are implementation-defined.
Revisions (0)
No revisions yet.