Moment.js Last Updated : 16 Jun, 2024 Comments Improve Suggest changes Like Article Like Report Moment.js is a JavaScript package that makes it simple to parse, validate, manipulate, and display date/time in JavaScript. It allows you to display dates in a human-readable way based on your location. It can be used in a browser using the script approach. Moment.js is also compatible with Node.js and can be installed via npm. Why Moment.js?You may find numerous simple ways to add, subtract, validate dates, retrieve the maximum and minimum dates, and so on in Moment.js. It's an open-source project, so you can easily contribute to it, and the add functionality in the form of plugins. You can parse the date into the desired format using parsing. We can also perform date validation. Steps to Install Moment.jsWe can install it in the following two ways. Method 1: Go to the official documentation of https://momentjs.com/ and download the latest moment.js file available and then add the link inside the script tag. Without downloading the file, you can also use the CDN link to run the code. <script type="text/JavaScript" src="https://MomentJS.com/downloads/moment.js"></script> Method 2: We can install it using npm. Make sure that you have Node.js and npm installed. npm install momentExample: In this example, we will get the current time in hours. index.js // Importing moment module const moment = require('moment'); var a = moment().hours(); console.log("Hours is: ",a); Run index.js file using below commandnode index.jsOutput: Hours is: 22 Comment More infoAdvertise with us Next Article Moment.js H hardiksm73 Follow Improve Article Tags : JavaScript Web Technologies Moment.js Tutorials Web-Tech Tutorials +1 More Similar Reads Moment.js Parsing Now Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed to get the current date and time. The moment() function is used to create a moment with the current date and time. Syntax: moment() | moment(undefined) | moment( 1 min read Moment.js Timer Plugin The Moment.js Timer Plugin is used for the creation of timers. It is an improvement over JavaScript's native timer. Essentially, it is a rewriting of the setInterval and setTimeout methods. It provides a list of functions concerned with creating and managing timers on top of moment duration objects. 1 min read Moment.js Parsing Object Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed with an object to parse dates represented as objects. The moment() function is used to create a moment using an object. Syntax: moment({unit: value, ...}) Parame 1 min read Moment.js Parsing String Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed with a string to parse dates represented as strings. The moment() function is used to create a moment using a string. Syntax: moment(String) Parameters: It take 1 min read Moment.js moment().toArray() Method The moment().toArray() method is used to return an array that is similar to the parameters of a new Date() object. The array contains the values for the year, month, day, hours, minutes, seconds, and milliseconds. Syntax: moment().toArray(); Parameters: This method does not accept any parameters: Re 2 min read Like