You can see this code in action by checking out this demo.Another annoying task that has simplified is date validation.In order to perform validation, simply pass a date string to the moment().subtract('days', 7); // subtracts 7 days to current date moment().subtract('months', 7); // subtracts 7 months to current date moment().subtract('years', 7); // subtracts 7 years to current date offers a way to calculate the difference between two dates. The unit of time can be specified using the optional second argument.The difference is calculated in milliseconds by default, but can also be returned in days, months, years, etc. If this is not included, then milliseconds are used.Fortunately, the library provides additional parameters that allow us to specify the exact pattern we’re passing in to help us avoid cross-browser inconsistencies.For consistency across all browsers and platforms, the above code should be parsed like the fowlloing.If you haven’t worked with dates at length before, this one might stump you.
is really an awesome library that simplifies date and time related manipulations and validations.
Since discovering Moment.js, an open source project, I’ve used it religiously to simplify validation, parsing and manipulation of dates on the client-side.
In this tutorial, I’ll help you get up and running with this ultra-useful Java Script date library.
is freely available for download from the project’s home page.
can be run from the browser as well as from within a application.
Often, we ask people to enter dates and, despite our best efforts and flashy tooltips asking them to input in a specific date format like "d/m/y", they ignore our instructions and provide "m/d/y" anyways.