One of the biggest frustrations developers deal with is working with dates. For an excellent overview of why dates are so complicated, check out JavaScript dates, trains, Passover, and Henry VIII by Curtis Autery.
When it comes to working with dates, JavaScript will make you want to hit your head against your desk. Even for simple tasks, working with JavaScript’s Date object can be a major hassle. It lacks a lot of basic functionality that you’d expect like being able to format a date/time a certain way, adding or subtracting from dates, working with locales, and a lot more.
There are hacky ways to accomplish these things as the thousands of StackOverflow posts about JavaScript dates can attest, but save yourself the trouble and check out moment.js.
Moment.js is an awesome library that makes working with dates in JavaScript a lot less painful. Dare I say it, maybe even enjoyable. Rather than give an incomplete introduction to its features here, scroll through the Moment.js docs page to see everything that you can do with it.
And next time you find yourself writing new Date
in your code, take 30 seconds to download moment.js and save yourself hours of frustration.