The Wayback Machine - https://web.archive.org/web/20240920023516/https://www.geeksforgeeks.org/dayjs-introduction-and-installation/
Open In App

DayJS Introduction and Installation

Last Updated : 08 Feb, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Features:

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

    <script src=”https://unpkg.com/dayjs@1.8.21/dayjs.min.js”></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:

Javascript




const dayjs = require('dayjs');
  
// 2021-02-08T03:08:30+05:30 - ISO 8601 standard
console.log(dayjs().format());
  
// 08 February 2021, 03:08:30 AM
console.log(dayjs().format('DD MMMM YYYY, hh:mm:ss A')); 
  
// 08-02-2021
console.log(dayjs().format('DD-MM-YYYY'));
  
// Monday
console.log(dayjs().format('dddd')); 
  
// Feb
console.log(dayjs().format('MMM'));
    
// 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

Output:

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.



Similar Reads

How to use the DayJS Library to work with Date & Time in JavaScript?
JavaScript has various useful packages for working with date and time. One such library is DayJS, which provides a simple and proper way to manipulate, format, and parse dates in JavaScript applications. Prerequisites:Node.js and npm JavaScriptSteps to Create Application and Installing PackageStep 1: Create a new folder for your project and navigat
2 min read
Svelte | Introduction and Installation
Svelte is the new methodology for creating web apps. It can be used in a small part of a code or in an entire single page application. It is a compiler not a framework, which is faster than other JavaScript libraries like ReactJS, AngularJS, VueJS. It is used to create reactive web apps. If any change occurs in the data that change will reflect on
2 min read
Introduction and Installation process of Gulp
Gulp can be defined as a task runner or a toolkit for automating time-consuming tasks such as magnification, concatenation, cache busting, unit testing and linting in web development. It uses Node.js as a platform and utilizes JavaScript code to help in running front-end tasks and large-scale web applications. These tasks can be run on PowerShell,
3 min read
Ant Design Introduction and Installation for Angular
Ant Design is a design pattern for enterprise-level products that can be integrated with other front-end frameworks such as Angular, React, or Vue. Ant Design official implementation is released with React but it can be used with other JavaScript frameworks. It is an open-source tool with approximately 50.4K GitHub stars, it is the world's second m
3 min read
MDBootstrap Introduction and Installation for Angular
Introduction: MDBootstrap (Material Design for Bootstrap) is a complete UI package that can be integrated with other frameworks such as Angular, React, Vue, etc. It is used to design a fully responsive and mobile-friendly layout using various components, plugins, animations to make it more attractive and user friendly which are compatible with othe
3 min read
SweetAlert Library Introduction and Installation with the Example
When building JavaScript-driven websites we often have the need to provide feedback to our users to let them know if the action they have performed has been successful or not. In the early days of the web, developers used to create messages using the window.alert() function. While alert() works in practice and it’s also consistent across browsers,
5 min read
AsgardCMS Introduction and Installation
AsgardCMS is made for developers. It is a full-featured, multilingual modular CMS developed on top of the Laravel framework. The built-in quick-development tools allow the developer to avoid spending their time on design and concentrate on functionality. It has the following characteristics: Completely Responsive: It has Bootstrap, which is fully r
3 min read
ASP Introduction and Installation
ASP stands for Active Server Page. It is commonly known as Classic ASP or ASP Classic. ASP is a server-side scripting language that is used for executing the scripts on the webserver. This technology was developed by Microsoft. It is an old but still useful tool used to create dynamic webpages. ASP is a program that runs inside a web server. Active
3 min read
Introduction and Installation of Nightmare.js
Nightmare is provided by Segment and is a high-level browser automation library. The goal for this Nightmare is to follow the path of the user actions (like goto, type, click, etc.), in order to expose few simple methods with an API that feels synchronous for each block of scripting, rather than deeply nested callbacks. It has been designed for aut
2 min read
Sugar.js Introduction and Installation
In this article, we will try to understand all the details which are associated with the library called Sugar-JS. Sugar is an open-source JavaScript utility library that is used for working with native objects. Users can define methods or use plugins to handle specialized use cases. Purpose of using Sugar-JS: The main purpose of using Sugar-JS is t
4 min read
Framer-Motion Introduction and Installation
Framer-motion is an open-source, production-ready animation and gesture library for React. It provides a low-level API to simplify animation and gesture integration into the application while maintaining HTML and SVG semantics. Features: Animations: It will automatically generate animations by setting values in the animate prop.Gestures: It support
3 min read
Backbone.js Introduction and Installation
Backbone.js is a lightweight JavaScript library that allows to develop and structure the client-side applications on the web. It provides structure to the application by providing the model with key-value binding and custom events, collections with a rich API of enumerate functions, views with declarative event handling, and connect it all to your
4 min read
Primer CSS Introduction and Installation
Primer CSS is a CSS framework that is built with the GitHub design system to provide support to enhance the development of websites. It is used to create the foundation of the basic style elements such as spacing, typography, and color. The systematic Primer CSS method ensures our patterns are steady and interoperable with every other. It is influe
3 min read
React Spring Introduction and Installation
React Spring is an animation library that makes animating UI elements simple. It is different from other animation libraries where someone has to deal with curves, easing, and time durations, all of which are in sync with each other. Platforms: React Spring is a cross-platform library, it supports React, react-native, web, and many more platforms.
2 min read
Materialize CSS Introduction and Installation
Materialize CSS is a design language that combines the classic principles of successful design along with innovation and technology. Materialize CSSMaterialize CSS is a modern front-end framework that enables developers to create visually appealing and responsive web applications with ease. Inspired by Google's Material Design principle, It's goal
2 min read
React Material-UI Introduction and Installation
Material UI is the most powerful and efficient React UI Framework to build an Application by adding Designs and Animations and using it with technical and scientific innovation. It is basically a design language that was developed by Google in 2014. It uses more Design and Animations, grid-system and provides shadows and lightning effects. Material
2 min read
Introduction and Installation of Heroku CLI on Windows machine
Heroku: It is a cloud based application deployment and management service. Heroku works on the container based design system and these smart containers are known as dynos . It runs application inside various dynos and each dyno is separated from each other. Installation of Heroku on Windows machine:Step 1: Download Windows installer Download the ap
2 min read
BootStrap Introduction and Installation
To begin Web development you may go through this article first. Grid SystemButtons, Glyphicons, TablesVertical Forms, Horizontal Forms, Inline FormsDropDowns and Responsive TabsProgress Bar and JumbotronBootstrap is a free and open-source collection of tools for creating websites and web applications. It is the most popular HTML, CSS, and JavaScrip
4 min read
Fluent UI Introduction and Installation for React
Microsoft's Fluent UI, unveiled in 2017, is an open-source, cross-platform design system that empowers developers to craft seamless applications like Office 365. It guarantees a uniform and polished design across diverse platforms for a cohesive user experience. Prerequisite:Node JS React JSFeatures of Fluent UI:Highly customizable.Up to date compo
2 min read
Introduction and Installation of Storybook for React
Storybook is an open-source UI development tool that facilitates the creation of reusable, well-documented components independently. It automates visual testing to prevent bugs and runs alongside the app in development mode. Additionally, it supports server-rendered component frameworks like Ruby on Rails. Prerequisites:NodeJS or NPMReact JSStorybo
2 min read
Vue.js Introduction &amp; Installation
Vue JS is a JavaScript framework used to design and build user interfaces. It is one of the best frameworks for Single Page Web Applications. It is compatible with other libraries and extensions as well. In the development field, there may be so many issues that can not be solved by using a single library, so the VueJS is compatible with other libr
2 min read
React-Motion Introduction & Installation
The react-motion package is a JavaScript animation library for the React applications which can be used for creating smooth and interactive animations. This uses the spring-based physics model, through which we can define animations with natural and dynamic movements. This library is mainly suited for complex UI animations and transitions. In this
4 min read
Remix Introduction & Installation
Remix JS is a Full Stack React-based framework that allows you to render code on the server which tends to result in better performance and Search Engine Optimization as compared to using React on the client-side. But Next JS already provides Server Side Rendering then how it is different from Next Js. Remix Js only supports server-side rendering.
5 min read
LAMP installation and important PHP configurations on Ubuntu
PHP is the Web development (Server Side Scripting Language) written and developed for web developers.It was developed by Rasmus Lerdorf in 1994, for maintaining his personal homepage. Later he added the feature to communicate with web forms and to connect with databases, named it as Personal Home Page Tools (PHP), Lerdorf wrote those using C binari
5 min read
Laravel | Installation and Configuration
Laravel is a PHP framework that makes building complex web applications a cakewalk. In this guide you are going to learn how to Install and Configure Laravel and get your first Laravel project running in your computer. Prerequisites: Basic knowledge of PHPPHP InstallationBasic knowledge of Terminal/Command Prompt Steps to install Laravel: Laravel a
2 min read
p5.js | SoundFile Object Installation and Methods
The SoundFile object is a part of the p5.sound which is a library of JavaScript. This object contains so many functions nearly 30+ functions are there. Each one of them is useful to design a sounded website. By using this object you can easily add audio into your website and play, pause, stop anything you want. To do so you just need to attach the
4 min read
CakePHP Framework | Installation and Configuration
CakePHP is an open-source framework for PHP based on a Model–View–Controller (MVC)-like architecture and modeled after the concepts of Ruby on Rails, which is powerful as well as easy to learn. It's a foundational structure for programmers to create web applications. Models, Views, and Controllers are used for the separation of business logic from
1 min read
PugJS Basics and Installation
Pug.js is a template engine for Node.js and browsers to render dynamic reusable content. At compile time, the template engine compiles our Pug template code to HTML. We can use variables in pug just like in JavaScript. At runtime, the template engine injects or replaces variables in a template file with actual values, and transforms the template in
3 min read
Sails.js Basics and Installation
Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it’s not a programming language. Most of the people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end serv
2 min read
AngularJS End to End (E2E) Testing Protractor Installation and Setup
The Protractor is an end-to-end test framework developed for Angular and AngularJS applications. It runs tests against the application interacting with it as a real user would, running in a real browser. Features of Protractor: Tests using browser: Protractor uses native events and browser-specific drivers to interact with the application.Build for
2 min read