toDateString() was Tue Sep 29 2020, while on my server, the result of. Notice anything? On my local computer, the result of. Here’s my local computer (the computer I’m standing at right now in the Eastern part of the United States):Īnd here is the webserver that I run my golf training application on: Imagine this - you‘ve been coding for 8 hours, your brain is a bit tired, and you console.log one of your dates during an intense debugging session: It seems like all the cool kids are using MomentJS these days (or if you’re even cooler - Luxon).ĭon’t worry, I’m not some JavaScript purist here telling you to always work with vanilla JS Date Objects - I just want to work through the core concepts that will make your life with Moment/Luxon much much easier.
Most people search for tutorials on JavaScript dates when all they needed was a review of how time works! (including myself) Before I start reading… What about MomentJS? As you read this post, you’ll realize that the difficult part of JavaScript dates is the non-JavaScript concepts like timezones and formatting standards. JavaScript dates aren’t actually that difficult. And if I had to guess, a few of you reading this are in a similar spot, so cheers to that! 🍻 Spoiler Alert It took me at least 3 years of programming before I finally sat down to understand this topic. If your dates don’t handle timezones correctly and you end up with an “off by 1” error, your user who missed their job interview is going to be FURIOUS with your app.
Furthermore, they might be the least exciting thing to learn about in JavaScript programming.īut what happens if you are building a Todo app - you know, the most overused web application in existence, and you want to add calendar reminder functionality? Posts A Complete Guide to JavaScript Dates (and why your date is off by 1 day)