Moment.js moment.duration().locale() Method
The moment().duration().locale() Method is used to return or set the locale of the duration. The locale of a duration will also affect methods like humanize() method that return the time in text, where different locales will affect the language of the text.
Parameters: This method accepts a single parameter as mentioned above and described below:
- String: This will be the string that specifies the locale that has to be applied.
Return Value: It returns the current locale 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().locale() Method.
The locale of durationOne is: en The humanized version of durationOne is: 9 months The humanized version of durationTwo is: 9 meses The humanized version of durationThree is: 9 mesi
The humanized version of durationA is: 9 months The humanized version of durationB is: 9 meses The humanized version of durationC is: 9 mesi
Please Login to comment...