Get the latest tech news
Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
le setting up this site itself, I ran into the following oddity: console.log(new Date('2025/05/28').toDateString()); // Wed May 28 2025 console.log(new Date('2025-05-28').toDateString()); // Tue May 27 2025 // Bonus: (omit leading 0) console.log(new Date('2025-5-28').toDateString()); // Wed May 28 2025 You may get different results on your machine! What's going on? A Date in JavaScript always represents a point in time (i.e. milliseconds since epoch).
ES5, to be released at the end of the year, includes a requirement for supporting a new standardized date-time format based heavily off of ISO 8601. This behavior has been maintained to the present day where every possible string accepted by the Date constructor falls back to local time except valid ISO date-strings like'2025-05-28'. What’s interesting looking at the timeline is that despite being designed as a standardized format, from its release in 2009 up until early 2020, there would never exist a point where the major browsers behaved consistently for missing offsets.
Or read this on Hacker News