MomentJS – Environment Setup


MomentJS – Environment Setup


”;


In this chapter, you will learn in detail about setting up the working environment of MomentJS on your local computer. Before you begin with working on MomentJS, you need to have the access to the library. You can access its files in any of the following methods −

Method 1: Using MomentJS File in Browser

In this method, we are going to need MomentJS file from its official website and will use it directly in the browser.

Step 1

As a first step, go to the official website of MomentJS https://momentjs.comYou will find the home page as shown here −

Setup

Observe that there is a download option available which gives you the latest MomentJS file available. Note that the file is available with and without minification.

Step 2

Now, include moment.js inside the script tag and start working with MomentJS. For this, you can use the code given below −

<script type = "text/JavaScript" src = " https://MomentJS.com/downloads/moment.js"></script>

Given here is a working example and its output for a better understanding −

Example

<html>
   <head>
      <title>MomentJS - Working Example</title>
      <script type = "text/JavaScript" src = "https://MomentJS.com/downloads/moment.js"></script>
      <style>
         div {
            border: solid 1px #ccc;
            padding:10px;
            font-family: "Segoe UI",Arial,sans-serif;
            width: 50%;
         }
      </style>
   </head>
   <body>
      <div style = "font-size:25px" id = "todaysdate"></div>
      <script type = "text/JavaScript">
         var a = moment().toString();
         document.getElementById("todaysdate").innerHTML = a;
      </script>
   </body>
</html>

Output