Author: Awais Farooq
-
Durations
MomentJS provides an important feature called durations which handles length of time for given units. In this chapter, you will learn this in detail. Methods Available with Durations The following table shows the methods available with duration for different units to be used with moment duration − Method Syntax Creating moment.duration(Number, String);moment.duration(Number);moment.duration(Object);moment.duration(String); Clone moment.duration().clone(); Humanize…
-
Customization
MomentJS allows to add customization to the locale created. This chapter discusses them in detail. The following list shows the customizations possible on localization − Sr.No. Localization & Description 1 Month NamesYou can add month names to the locale customization. 2 Month AbbreviationThis method helps in customizing the month abbreviations. 3 Weekday NamesThis method helps in…
-
Internationalization
Internationalization is one of the important features in MomentJS. You can display Date and Time based on localization, in other words, based on the country/region. The locale can be applied to specific moment if required. This chapter discusses in detail about how to make apply locale globally, locally, work with locale using Node.js, in browser,…
-
Date Queries
MomentJS provides methods to query the date/time for leap year, date comparison, date validation etc. This chapter discusses them in detail. Methods for Querying Date in MomentJS The following table shows methods available in MomentJS and their syntax for querying date − Method Syntax Is Before moment().isBefore(Moment|String|Number|Date|Array);moment().isBefore(Moment|String|Number|Date|Array, String); Is Same moment().isSame(Moment|String|Number|Date|Array);moment().isSame(Moment|String|Number|Date|Array, String); Is After moment().isAfter(Moment|String|Number|Date|Array);moment().isAfter(Moment|String|Number|Date|Array, String);…
-
Formatting Date and Time
MomentJS provides formats to display date in different ways. There are methods available which tells the time from a given moment, from the current moment, difference between two moments etc. It can display date in JSON format, Array, Object, String etc. Methods to Format Date and Time The following table shows a list of methods…
-
Manipulate Date and Time
MomentJSprovides various methods to manipulate Date and Time on the moment object. This chapter deal with all such methods in detail. Methods to Manipulate Date and Time The following table shows the methods available in MomentJS which helps in manipulating the Date and Time as required − Sr.No. Method & Syntax 1 Addmoment.add() 2 Subtractmoment.subtract()…
-
Getter/Setter
MomentJS has many methods to get/set the date inputs. Get will allow us to read the required input unit and set will allow to modify the input unit. This chapter discusses in detail the get/set methods to be used on the moment. The following table shows the get/set methods available − Method Syntax Millisecond moment().millisecond(Number)moment().millisecond();moment().milliseconds(Number);moment().milliseconds();…
-
Date Validation
MomentJS handles date validation in an easy way. You need not write lots of code to validate date. isValid() is the method available on moment which tells if the date is valid or not. MomentJS also provides many parsing flags which can be used to check for date validation. Parsing Flags MomentJS provides the following parsing flags in…
-
Parsing Date and Time
MomentJS has many easy to use methods which helps in parsing Date and Time. It can parse dates in the form of object, string, array, JavaScript native date object etc. This chapter discusses them in detail. Parsing Date MomentJS gives wrapper object as output when moment() is called. You can observe the following when you console the…
-
Introduction
In this chapter, we will discuss how to work with MomentJS using RequireJS and MomentJS and TypeScript. MomentJS and RequireJS To understand the working of MomentJS using RequireJS, let us analyze a working example with MomentJS and RequireJS. The folder structure of the corresponding app is shown in the following image − You can obtain the require.js file…