MomentJS - Using Locale in Browser


Advertisements

We can start working with locale by including the locale file in script tag. You can get the minified files for all locales from the MomentJS home page as shown below −

Browser

The same can be included in your application as shown here −

Example

<html>
   <head>
      <title>MomentJS - Adding locale</title>
      <script type="text/JavaScript" src="https://MomentJS.com/downloads/moment.js"></script>
      <script type="text/JavaScript" src="https://MomentJS.com/downloads/moment-with-locales.js"></script>
      <style>
         div {
            border: solid 1px #ccc;
            padding:10px;
            font-family: "Segoe UI",Arial,sans-serif;
            width: 40%;
         }
      </style>
   </head>
   <body>
      <h1>MomentJS - Adding locale</h1>
      <div style="font-size:25px" id="currentdate"></div>
      <br/>
      <br/>
      <div style="font-size:25px" id="changeddate"></div>
      <script type="text/JavaScript">
         moment.locale("pt");
         var a = moment().format('LLLL');
         moment.locale("hi");
         var b = moment().format('LLLL');
         document.getElementById("currentdate").innerHTML = "Output locale: " + a;
         document.getElementById("changeddate").innerHTML = "Output in hindi locale: " + b;
      </script>
   </body>
</html>

Output

momentjs_internationalization.htm
Advertisements