![]() |
The moment().duration().months() method is used to get the month of the duration. This method returns a value between 0 and 11. This method is different from the asMonths() method which returns the length of the given duration in months. Syntax: moment().duration().months(); Parameters: This method does not accept any parameters. Return Value: This method returns the months (0-11) of the duration. Note: This will not work in the normal Node.js program because it requires an external moment.js library to be installed globally or in the project directory. Moment.js can be installed using the following command: Installation of moment module: npm install moment The below examples will demonstrate the Moment.js moment.duration().months() Method. Example 1: Javascript
Output: durationOne months is: 9 durationTwo months is: 7 Example 2: This example will help to understand the difference of this method with asMonths() for a better understanding. Javascript
Output: Length of durationA in months is: 11.499209429351732 durationA months is: 11 Length of durationB in months is: 14.718988069570218 durationB months is: 2 Reference: https://momentjs.com/docs/#/durations/months/ |
Reffered: https://www.geeksforgeeks.org
Node.js |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |