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()); // 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). This is more apparent when pri...
Read more at brandondong.github.io