DEV Community

Cover image for What is moment.js alternative in Javascript?
Raksha for Canopas Software

Posted on

What is moment.js alternative in Javascript?

Most web developers have used moment.js. Do you know what's the alternative?

Are you looking for a Moment.js alternative in Javascript?

In one of our laravel projects, after upgrading dependencies, the docker build suddenly started throwing an error of moment.js.

On debugging, I noticed that moment.js was now in maintenance mode and they recommends using different libraries as an alternative.

As our requirements for date and time are not much complex, we decided to use javascript’s default Date() object and comes up with this article.

We've gathered a few alternatives that you can use in your projects.

Here's what you'll learn?

  • Get the year, month, date, day, and time
  • First and Last day of the month
  • Add and Subtract day, month, year, time
  • Get and Set the timezone for the date
  • Get dates in various formats

For implementation detail, check out our blog.

Top comments (4)

Collapse
 
etienneburdet profile image
Etienne Burdet

Modern alternative: Luxon (immutable, more options etc.)

Another approach I really like: using Date indeed, but with date-fns. Very functionnal, immutable, minimal, yet don't reinvent the wheel on formatting, adding etc.

Date alone is not enough though.

Collapse
 
mr_ali3n profile image
Vaibhav Mehta

Checkout day.js, pretty compact and gets the job done

Collapse
 
eshimischi profile image
eshimischi

day.js is one of the main alternatives

Collapse
 
stephenwhitmore profile image
Stephen Whitmore

Their documentation has some suggestions.