Last updated on November 22, 2022
As a front-end developer, I know that moment.js is the oldest date library, and whenever I thought to work with date manipulation, validation, or date parsing the moment.js is the first library that comes to my mind for use in the project. But comparatively, day.js’s usage will be going up because according to moment.js officials they won’t be adding any new feature to the library. They also recommended day.js as an alternative on their project status page.
We can’t say the Moment.js is dead but it is not recommended as a library to use in new projects. According to the team, they won’t be making any changes in the mutable API. Nor, will there be any additional features or release of a new version on moment.js.
Day.js can be installed as a dependency through NPM and also added to the HTML page through CDN.
To install through npm, open your terminal and run below command.
npm install dayjs
After installation of the package we can import into our script file like this.
const dayjs = require('dayjs')
dayjs().format()
Also you can use the CDN in your project like the below code. To install through CDN, add below script in your HTML page that will include day.js.
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>
<script>dayjs().format()</script>
This article demonstrates reasons for using day.js instead of moment.js. According to moment.js officials, they won’t be adding any new features to the library; that’s why with time it will be obsolete.