Skip to content
the poor coder

How to install moment.js

Poor Man
Published
Reading time
1 min read

Installing moment.js is easy and straightforward. All you need to do is to include the moment.js JavaScript file in your HTML page. This can be done in two ways:

1. By adding a <script> tag to your HTML page, pointing to the moment.js file you have downloaded:

HTML
<script type="text/javascript" src="moment.js"></script>

2. By using a Content Delivery Network (CDN) to host the moment.js file. This is the preferred way, as it eliminates the need to download and store the moment.js file on your server. A CDN is a network of servers distributed across multiple locations. By pointing your browsers to the CDN, they can access the moment.js file without having to download it. Simply add the following line to your HTML page:

HTML
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

Once the moment.js file is included, you can use the moment global object to access its methods. For example, to create a moment object representing the current date and time, you can use the following code:

JavaScript
var now = moment();

You can also use moment.js to parse and validate dates, format dates, manipulate and display them in different formats, calculate date and time durations, and much more. See the moment.js documentation for more details.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC