Skip to main content Accessibility Feedback

An easier way to work with dates in vanilla JS

Earlier this year, I wrote a little JS app called Timezones to help me easily calculate times across timezones. It’s super handy for planning meetings and such.

One thing that was particularly hard was working with times and dates.

The Date() method is awesome, and formatting dates isn’t that hard. The real challenge was adding things like hours, minutes, and seconds to a date.

A lot of people use the Moment.js library for this, but I recently discovered Day.js, a 2kb alternative to uses the same API.

It’s well documented, can be installed using a humble script element, and works all the way back to IE9.

If you need to work with dates and times on a project, I highly recommend checking out the project on GitHub.