Thank Java for Better JavaScript Dates
steele.blue·33w
Preview
Report Post

Apr 15, 2025

I gave a lightning talk at NebraskaJS about the complex, decades-long relationship between JavaScript and Java’s Date APIs:

The first half was a bit of a troll; I used a Java REPL (anonymized to look like Node) to demonstrate some of the more famously unexpected behavior in the Date class:

var date = new Date("March 20 2025");
date.getMonth(); // returns 2
date.getDay(); // returns 3
date.getYear(); // returns 125??

This code is syntactically correct Java and JavaScript, and behaves identically in both languages. One of the gifts of being told to “make it like Java” when adding dates to a ten-day-old language.

Java, of course, got markedly improved…

Similar Posts

Loading similar posts...