Great question! In JavaScript, the dates "2025/05/28" and "2025-05-28" can be parsed differently depending on the context — particularly due to how Date.parse() and the Date constructor interpret date strings.
TL;DR:
"2025/05/28" is interpreted as a local time date.
"2025-05-28" is interpreted as a UTC (Coordinated Universal Time) date if used in ISO 8601 format and parsed according to ECMAScript standards.
🧠 Why does this happen?
JavaScript's Date object handles date strings differently based on their format, especially when it comes to ISO 8601 format (YYYY-MM-DD):
🔹 Case 1: "2025/05/28"
This string uses slashes /, so it’s not in ISO format. The browser parses it using a platform-dependent parser, usually treating it as a local time date.
new Date("2025/05/28")
// → Interpreted as local time (e.g., your system timezone)
🔹 Case 2: "2025-05-28"
This string is in ISO 8601 format (YYYY-MM-DD). According to the ECMAScript specification:
If the date-only form is used (e.g., "2025-05-28"), the time is assumed to be midnight at UTC (not local time).
new Date("2025-05-28")
// → Interpreted as UTC time (midnight of that day in UTC)
🌍 Example with Timezone Offset
Let's assume you're in a timezone like PDT (UTC-7).
console.log(new Date("2025/05/28")); // e.g., Wed May 28 2025 00:00:00 GMT-0700 (PDT)
console.log(new Date("2025-05-28")); // e.g., Tue May 27 2025 17:00:00 GMT-0700 (PDT)
Why May 27 for the second one?
Because:
"2025-05-28" is parsed as 2025-05-28T00:00:00Z (UTC).
- When converted to your local time (UTC-7), that becomes
2025-05-27T17:00:00.
✅ Best Practices
To avoid confusion:
✔️ Use explicit formats:
If you want local time, construct the date manually:
new Date(2025, 4, 28) // Months are 0-indexed (April = 4)
✔️ Or force UTC explicitly:
Date.UTC(2025, 4, 28) // Midnight UTC on May 28
❌ Avoid ambiguous date strings:
Parsing strings like "2025-05-28" or "2025/05/28" can lead to different results across browsers or environments.
📚 Summary
| Format | Interpretation | Time Zone |
|---|
"2025/05/28" | Local time | System default |
"2025-05-28" | UTC (per spec) | Always UTC |
Let me know if you'd like to see a table showing the difference in output for specific timezones!