Working with dates and time in Javascript has always been an unpleasant process. Although the Javascript API provides us with special methods for working with dates and time, but they are often not enough. That's why separate libraries were created to make it easier and extend with additional methods to work on time and dates in Javascript.

Moment.js

What is Moment.js?

Moment.js is an open source library for Javascript that helps on working with dates and time. It mainly facilitates parsing, validation and display of time and date. We can run Moment.js from a browser, but also from within Node.js. Moment.js is a good choice when, we want our application to run also on older browsers.

 

Are you looking for a contractor working with Moment.js ?
logo

First steps with Moment.js

To install moment.js we will need a package manager, it can be npm or yarn. The following command shows the installation of Moment.js via npm.

npm install moment

 

After installation, we can import our library into the project and start using it.

const moment = require('moment');
const today = moment();
console.log(today.format('YYYY-MM-DD'));

This format will display the date in the order YEAR-MONTH-DAY.

 

Attention, Moment.js is no longer supported!

The developers of the library have decided to suspend the project and its status has been changed to "legacy". Moment.js was used in a really large number of projects, but unfortunately it is too outdated to work with modern Javascript code. That's why the project developers themselves encourage the use of another library such as Luxon.

Our offer

Web development

Find out more

Mobile development

Find out more

E-commerce

Find out more

UX/UI Design

Find out more

Outsourcing

Find out more

Related articles

Show all articles