Javascript's Date Library Sucks

Lucas Schiavini | ルスキラ
2 min readJan 31, 2023

Don’t you all love beautiful consistent computer languages?
Neither do I.

Yeah, I really have this deep hatred for javascript’s Date library.

But wait, there is more!

Let’s try creating more dates using strings on the constructor:

Hmmm, why did it create date1 on the 5th of February instead of the 6th? Let us try separating the date manually and putting it in the format Date(YEAR, MONTH, DAY) and see what we get.

WHAT? Alright, it put it in the right day, but not the right month. Maybe the months are numbered from 0 to 11 then (When we use numbers, not strings).

Yeah, I was right, it uses month as 0 to 11, and day as 1 to 31 apparently.

Let’s try to compare date1 and date2 then.

Good lord, how inconsistent!

Do you know what is the saddest part of this? I’m not the first to encounter these inconsistencies, and I won’t be the last.

God bless us all.

😗 Enjoy my writing?

Like my content? Feel free to Buy me a Coffee ☕.

Subscribe to my exclusive email newsletter here.

Forward to a friend and let them know where they can subscribe (hint: it’s here).

Anything else? Just say hello in the comments :).

Join an Exclusive Tech Friendly Community! Connect with like-minded people who are interested in tech, design, startups, and growing online — apply here.

--

--