

Using the moment.js library is very simple and has been prepared for all major project types: from simply using the minified version directly in the script tag, to using it in a node.js project using np or nuget. If you write in TypeScript, you get types in the package, so you don't need to install types from DefinitelyTyped.
This library covers a huge area of application.
Let's start with a simple example of creating a basic moment object:
var m = moment();
The above construct creates a moment object representing the current time. When the above function is called with a parameter, we can expect different behaviour depending on the parameter type. First of all, we can "pack" a Date object into the moment object. If we provide a number, it will be treated as a Unix timestamp expressed in milliseconds. If we provide a string, then an attempt will be made to parse this string into a date. The library is of course prepared for different variants of date and time formats, from typical American formats to more familiar looking formats like 'YYYY-MM-DD'. What is important, if the parsing fails, we will not see any error or exception - the object will be created, but the correctness of the object can be checked by running the isValid() method. Apart from providing the string to be parsed, we can also provide a specific format:
var m = moment('2018-10-14', 'YYYY-MM-DD');
If we are not sure of the format used, we can specify more. The second parameter is then an array of strings.
I think that such a wide range of date parsing capabilities will satisfy everyone, who at least once had to face the validation of user input data. This applies mainly to the frontend, but nothing prevents the library to work on the backend and validate data coming from e.g. REST.
Another important feature of the library is the ability to manipulate time. We have at our disposal such basic methods as setting individual date/time fragments. But what I appreciate the most is the ability to add and subtract. I think you have encountered more than once a problem like "when will it be three months from February 29". We do then like this:
moment(). add(3, 'months');
The substract method works analogously. On the other hand, if we have a date where we would like to reset the time to midnight, then this method will come in handy:
moment(). startOf('day');
One note here - all operations on the moment object change it. So let's be careful when passing the moment object to a function where we perform the above-mentioned operation. Because if it was not our intention, the passed object will be changed. To avoid this, we need to make a copy of the passed object using the clone() method. Transferring the date between the frontend and backend is best done by sending it in a unix timestamp, in which case a method with the intuitive name unix() will be useful:
moment().unix();
Finally, formatting. It is de facto the opposite of parsing and the same formatting rules are used here as in parsing, e.g:
moment().format( 'YYYY-MM-DD');
The library has a whole host of other methods that make date and time operations much easier: