MomentJS - Normalize Units


Advertisements

This method allows to normalize the units used in your program. Note that the methods which makes use of units, such as moment().get(‘h’) or moment().get(‘hours’) are same.

In case you want to define the alias for units, you can do so using the Normalize method. Using the year as y or YEar or yEARs will fallback to year using normalizeUnits.

Syntax

moment.normalizeUnits(String);

Example

moment.normalizeUnits('y');
moment.normalizeUnits('Y');
moment.normalizeUnits('yEar');
moment.normalizeUnits('yeArs');
moment.normalizeUnits('YeARS');

Output

Normalize

Example

var m = moment.normalizeUnits('M');
var a = moment.normalizeUnits('MONTHS');
var b = moment.normalizeUnits('Months');
var c = moment.normalizeUnits('MonTh');

Output

Normalize Months
momentjs_utilities.htm
Advertisements