MomentJS - Months


Advertisements

This method will give no of months in a duration. It will return value from 0-11. To get the length of months in a given duration use moment.duration().asMonths();

Syntax

moment.duration().months();
moment.duration().asMonths();

Example

var m = moment.duration(100, "months").months();
var asmins = moment.duration(500, "months").asMonths();

Output

Months

Years

This method will give no of years.moment.duration().asYears()gets the length of the duration in years.

Syntax

moment.duration().years();
moment.duration().asYears();

Example

var m = moment.duration(500, "years").years();
var asmins = moment.duration(500, "years").asYears();

Output

Years
momentjs_durations.htm
Advertisements