Why are 2025/05/28 and 2025-05-28 different days in JavaScript? 2025-05-28 While setting up this site itself, I ran into the following oddity: console.log(new Date('2025/05/28').toDateString()); console.log(new Date('2025-05-28').toDateString()); console.log(new Date('2025-5-28').toDateString()); You may get different results on your machine! A Date in JavaScript always represents a point in time (i.e. milliseconds since epoch). This is more apparent when printing out the full date string:const date = new Date('2025/05/28'); console.log(date); console.log(date.toDateString()); In this case, the passed-in date string is being interpreted as a timestamp in my local time zone. toDateString() also operates relative to the local time and so we get the same day-of-the-month back out.The difference with '2025-05-28' is in parsing behavior; the string is interpreted as UTC and so ends up at a different point in time:const date = new Date('2025-05-28'); console.log(date); console.log(date.toDateString()); Why the discrepancy? After digging through the code and commit histories of Chrome/Firefox/Safari, I’ve reconstructed a timeline: In 2009, these browsers supported parsing a mishmash of date-time formats. When time zone offsets are not explicitly specified in the string, they all fall back to using local time, including for a date string like '2025/05/28'. 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 format is broken up into date-only forms like '2025-05-28' and date-time forms like '2025-05-27T17:00-07:00' where the ending UTC offset is optional. What does the spec say about time zone interpretation for date-only forms (which never have an offset) or date-time forms missing an offset? Only that The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. (Gee, thanks…) Firefox is the first to ...
First seen: 2025-05-28 07:59
Last seen: 2025-05-28 13:00