Skip to content
Related Articles
Open in App
Not now

Related Articles

DayJS Introduction and Installation

Improve Article
Save Article
Like Article
  • Last Updated : 08 Feb, 2021
Improve Article
Save Article
Like Article

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.


  1. It is easy to use and since it has the same API as moment js it is very much easy to work with it.
  2. It has gained a lot of popularity because of its small size.

Installation of DayJS:

  • You can visit “” 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.

    <script src=””></script>

  • 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.

Filename- index.js:


const dayjs = require('dayjs');
// 2021-02-08T03:08:30+05:30 - ISO 8601 standard
// 08 February 2021, 03:08:30 AM
console.log(dayjs().format('DD MMMM YYYY, hh:mm:ss A')); 
// 08-02-2021
// Monday
// Feb
// Feb 8th,21 
console.log(dayjs().format("MMM D[th],YY")); 

Run the file: In the terminal run the following command to execute the index.js file.

node index.js


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.

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!