Article summary
Ask any developer what the “weirdest” part of JavaScript is, and most will mention its quirky type coercions, bizarre equality operators, or NaN oddities. But lurking underneath all that chaos is something even more cursed: the Date object. Let’s look into the cursed legacy of JavaScript’s Date class.
Originally lifted straight from Java’s java.util.Date (JDK 1.0), the Date API in JavaScript inherited decades of questionable design. Unfortunately, unlike Java, JavaScript can’t simply deprecate and replace it — the web demands backward compatibility. That means the Date quirks of 1995 are still haunting us in 2025.
A Tour of the Madness
Consider these surprises when working with new Date():
Year parsing behaves inconsistently:
new Date(0)gives January 1st, 1970new Date(50)lands you in 1950- Past
99, years reset to0100
Invalid inputs don’t fail cleanly.
const d = new Date("not-a-real-date");
d.toString(); // "Invalid Date"
d.getTime(); // NaN
d.toISOString(); // RangeError: Invalid time value
The same invalid object can return a special string, silently yield NaN, or throw an error — three different failure modes for a single “invalid” state. And since "Invalid Date" is still a real object, it evaluates truthy in conditionals. Detecting bad dates requires explicit checks:
if (isNaN(d.getTime())) {
console.error("Invalid date value!");
}
Parsing differs across browsers.
- V8-based environments (Chrome, Node, Bun) allow patterns Firefox outright rejects. Even offsets and shorthand notations vary between engines.
The result: behavior that feels more like trial-and-error than a reliable API.
Better Options Exist
Until the incoming Temporal API becomes more widely available, most developers lean on libraries like Day.js or date-fns. These libraries abstract away the inconsistencies and provide predictable APIs for formatting, parsing, and working with time zones.
Dates and time zones are already some of the hardest problems in software. Combined with JavaScript’s quirks, they’re downright cursed. The key lesson? Don’t reinvent the wheel. Reach for a battle-tested library or Temporal, and save yourself the descent into madness.