DEV Community

Arnaud Dagnelies
Arnaud Dagnelies

Posted on

1 1

Date.toLocaleDateString() is wrong! ...how to fix it?

Let's cut to the chase with an example:

new Date('2022-02-09').toLocaleDateString('de-DE')
Enter fullscreen mode Exit fullscreen mode

This outputs 9.2.2022 ...which is the wrong format!

The common expected format would be 09.02.2022!

The first one is not 100% wrong though, it's more like an unusual but tolerated format in Germany. However, what shows in the windows task bar, in apps, in official documents, and so on, is always 09.02.2022 here in Germany. The other just shows sometimes up in handwritten letters.

There are countless related bug reports complaining about this on the web, in all kind of unrelated projects, since ages. Still, it doesn't seem to budge.

So I tried to dig up the "official" format:

I must confess that despite searching for quite some time, I failed too to discover where this "wrong" d.m.yyyy comes from. Despite every browser seem to implement it, I haven't found the official reference regarding these date format patterns.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay