Day js is a lightweight date and time manipulation library. It is an alternative to moment js with the same modern API. The latest version of day js has a size of 7Kb (minified) and 2Kb (Gzipped). Due to its small size, it takes less time to load and thus improving the overall performance of the application.
- It is easy to use and since it has the same API as moment js it is very much easy to work with it.
- It has gained a lot of popularity because of its small size.
Installation of DayJS:
- You can visit “https://day.js.org/docs/en/installation/installation” for the documentation. The package can be installed with this command.
npm install dayjs
- You can also add a CDN link to your project. The link is given below.
- After installing, you can check the installed version of the package with this command.
npm ls dayjs
- To start working with DayJS create a file with the name index.js. The package can be included in the index.js with this command.
const dayjs = require('dayjs');
Project Structure: The project structure will look like below image.
Run the file: In the terminal run the following command to execute the index.js file.
The MomentJS Module does the same work as DayJS but when you have the performance of web application as the utmost priority, moment js can pose a problem because of its complex API and large bundle size. Dayjs is a great alternative to moment js with a very small size as compared to the moment js. So, this is how we can use DayJS in our application to manipulate, validate and display date and time.