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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of javascript

javascript

Photo of different days

different days

Photo of 2025/05/28

2025/05/28

Related news:

News photo

A thought on JavaScript "proof of work" anti-scraper systems

News photo

Show HN: SQLite JavaScript - extend your database with JavaScript

News photo

JavaScript's New Superpower: Explicit Resource Management